stopPropagation

iLove9ouHenry 2011-10-17 02:29:41
为什么要阻止冒泡事件?
...全文
51 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
光曰不日 2011-10-17
  • 打赏
  • 举报
回复
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<script src='http://code.jquery.com/jquery-latest.js'></script>
<script type="text/javascript">
$(function(){

$('.div1,.div3').width(200).height(200);
$('.div2,.div4').width(70).height(70).css('margin','10px 10px');
$('div').css('border','solid 1px red');
$('.div1,.div2,.div3').click(function(){
alert($(this)[0].className)
});
$('.div4').click(function(e){
alert($(this)[0].className)
e.stopPropagation();
});
})

</script>
<style>
</style>

</head>

<body>
<div class='div1'>div1
<div class='div2'>div2点我冒泡
</div>
</div>
<div class='div3'>div3
<div class='div4'>div4点我不冒泡
</div>
</div>
</body>
</html>

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧