2014-09-04 34 views
0

我可能在這裏忽略了一件小事,但是有人可以告訴我爲什麼div中的文本沒有改變,當我按下按鈕?使用Jquery函數的按鈕不起作用?

<body> 
    <div id="testing">Hello Again :-)</div> 
    <br/><br/> 
    <button onclick="changingText()">Change Me!</button> 
</body> 

<script type="text/javascript"> 
    function changingText() 
    { 
     //This is the setter of the innerHTML property in jQuery 
     $('#testing').html('Hello World'); 

     //This is the getter of the innerHTML property in jQuery 
     //var helloWorld = $('#output').html(); 
    } 
</script> 
+3

你有調用jQuery庫嗎? – kefy 2014-09-04 03:28:23

+0

檢查您的瀏覽器控制檯,看看是否有任何錯誤 – 2014-09-04 03:28:41

+0

你的腳本很好 - http://jsfiddle.net/arunpjohny/n5p2yoh6/1/ – 2014-09-04 03:29:37

回答

0
<body> 
    <div id="testing">Hello Again :-)</div> 
    <br/><br/> 
    <button onclick="changingText()">Change Me!</button> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     $('#btnChangeText').click(function (event) { 
      $('#testing').html('Hello World'); 
      event.preventDefault(); 
     }); 
    }); 
</script> 

</body> 

請讓我知道,如果任何事情出錯。 謝謝