【问题标题】:Button with Jquery function is not working?带有 Jquery 功能的按钮不起作用?
【发布时间】:2014-09-04 03:24:33
【问题描述】:

我可能在这里忽略了一个小东西,但是有人可以告诉我为什么当我按下按钮时div 中的文本没有改变??

<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>

【问题讨论】:

  • 你有调用jquery库吗?
  • 检查您的浏览器控制台,看看是否有任何错误
  • 你的脚本很好 - jsfiddle.net/arunpjohny/n5p2yoh6/1
  • 伙计,我觉得自己很愚蠢 - 我忘了图书馆.....
  • 我已经预料到了……哈哈:D

标签: jquery html innerhtml


【解决方案1】:
<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>

如果有任何问题,请告诉我。 谢谢

【讨论】:

    猜你喜欢
    • 2013-08-13
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多