这是我的代码,没有任何事情发生:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-git.js"></script>
<script>
$(".clickMe").click(function() {
alert('hi!');
// Do other stuff
});
</script>
</head>
<body>
<div class="clickMe">Click Me!</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是,单击"clickMe"div时没有任何反应.
谢谢!
让文件准备好
$(function(){
$(".clickMe").click(function() {
alert('hi!');
// Do other stuff
});
})
Run Code Online (Sandbox Code Playgroud)
你有它的方式,div还没有可用(没有加载DOM)所以,没有添加点击处理程序.您需要等待文档可用.的.就绪()是将被用于这一点.
$(document).ready(function() {...})
$(function() {...}) - Shortcut
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
142 次 |
| 最近记录: |