<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>作用域</title>
<style>
p{ width: 300px; height: 300px; margin: 0 auto; background: pink;}
</style>
<script src='jquery-1.11.2.min.js'></script>
<script>
$(function() {
var a=true;
if(a==true){
alert('ok')
$('p').click(function(event) {
alert('第一次'+a);
a=!a;
alert('第1.1次'+a);
$('p').click(function(event) {
alert('第二次'+a)
});
});
}
});
</script>
</head>
<body>
<p></p>
</body>
</html>
不知道为什么当a是false的时候 第一个点击事件也能执行
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的代码逻辑稍有问题,看:
当
p点击的时候,如果a为真,则····你的:
当
a为真的时候,点击p则····这样试试:
第一次进去 进行了事件绑定