1

我整晚都遇到这个问题。我将单击按钮,但我没有得到任何数据或警报。请帮我。所以对不起我的英语不好。我会努力学习的。

  
 $(document).ready(function() {
     $("#test-click").on("click",function() { 
        alert('1');
     });
 });
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="test-click">testClick</button>

4

2 回答 2

1

你可以试试这个。它的工作。

 $(document).ready(function(){
$("#test-click").click(function(){
alert("1");

})
});
于 2016-10-25T07:28:29.627 回答
0

当然是!你的代码不工作。因为.on()事件发生在 jquery 1.7.x 版本之后。请使用.live()事件而不是.on()事件。或者使用最新的 jquery 版本。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
    $(document).ready(function(){
    $("#test-click").live("click",function(){ 
        alert('1');
    });
    });

</script>
<button type="button" id="test-click">testClick</button>

于 2016-10-25T07:20:24.603 回答