Jquery e.stopPropagation()终止冒泡无效!
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><title></title><scriptsrc="js/jquery-...
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="js/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#div1").mouseover(function (e) {
alert("mousemove");
e.stopPropagation(); //终止冒泡
});
})
</script>
</head>
<body>
<div id="div1" style=" border:solid 1px red">
11111111111111111111111111111111111111<br />
11111111111111111111111111111111111111111111111111111<br />
11111111111111111111111111111<br />
111111111111111111111111111111111111111111111111111111<br />
1111111111111111111111111111111111111111111111111111<br />
11111111111111111111111111111111111111111111<br />
<div>aaaaaaaaaaaaaaaaaa</div>
<div>bbbbbb</div>
<div>cccccccccccccccc</div>
<input type="text" />
</div>
</body>
</html> 展开
<head>
<title></title>
<script src="js/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#div1").mouseover(function (e) {
alert("mousemove");
e.stopPropagation(); //终止冒泡
});
})
</script>
</head>
<body>
<div id="div1" style=" border:solid 1px red">
11111111111111111111111111111111111111<br />
11111111111111111111111111111111111111111111111111111<br />
11111111111111111111111111111<br />
111111111111111111111111111111111111111111111111111111<br />
1111111111111111111111111111111111111111111111111111<br />
11111111111111111111111111111111111111111111<br />
<div>aaaaaaaaaaaaaaaaaa</div>
<div>bbbbbb</div>
<div>cccccccccccccccc</div>
<input type="text" />
</div>
</body>
</html> 展开
推荐于2016-08-15
展开全部
在火狐Firefox、opera、IE下阻止蠢笑冒泡事件是不同的代码的,火狐下使用的是event.stopPropagation(),而闷迅IE下使用的是cancelBubble,jQuery 可以使用e.stopPropagation()就可以兼容了,如果是纯粹的JavaScript需蚂档此要下面的代码来统一:
if (event.stopPropagation) {
// this code is for Mozilla and Opera
event.stopPropagation();
}
else if (window.event) {
// this code is for IE
window.event.cancelBubble = true;
}
if (event.stopPropagation) {
// this code is for Mozilla and Opera
event.stopPropagation();
}
else if (window.event) {
// this code is for IE
window.event.cancelBubble = true;
}
追问
我的代码就是用的 jquery e.stopPropagation(),为啥ie下不行呢。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询