<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script type="text/javascript">
$("#myBtn").on("click",function(){
alert('myBtn Clicked');
});
</script>
</head>
<body>
<button type="button" id="myBtn">Sample</button>
</body>
</html>
对于上述代码,单击事件未触发。我使用 JSFiddle 它工作正常。在委托的情况下它工作正常。我用于委托的代码如下
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).on("click","button",function(){
alert('myBtn Clicked');
});
</script>
</head>
<body>
<button type="button" id="myBtn">Sample</button>
</body>
帮我解决这个问题......