一般情况下 在同一个界面里面基本不会绑定无效的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dom</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").on("click",function(){
alert(111);
});
});
</script>
</head>
<body>
<button>点我!</button>
</body>
</html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
另一种情况下 click在B.js里面被创建的
$(function() {
$("#index").click(function () {
alert(111);
})
})
PS:如果现在A.html刚加载($().ready)就要使用$("#index").click()的话是无效的
PS:由于$(function(){})是DOM元素加载完毕后执行的函数,因此函数外部的绑定click事件函数先与$(function(){})执行