您的位置:首页 > Web前端 > JQuery

jquery 事件冒泡 解决 ie firefox 兼容性问题

2016-03-08 17:00 267 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>在此处插入标题</title>
<style>
#div1 {
width: 400px;
height: 400px;
background-color: red;
}

#div2 {
width: 300px;
height: 300px;
background-color: green;
}

#div3 {
width: 200px;
height: 200px;
background-color: blue;
}
</style>
<script language='javascript' src='../jQuery/jquery.js'></script>
<script>
$().ready(function() {

//点击事件 div1
$('#div1').bind('click', function() {
alert('div1');
});

//点击事件 div2
$("#div2").bind("click", function(event) {
alert('div2');
event.stopPropagation();
});

//点击事件 div3
$("#div3").bind("click", function(event) {
alert('div3');
//弹出消息框后,取消事件冒泡
event.stopPropagation();
});
});
</script>
</head>
<body>
<div id='div1'>
<div id='div2'>
<div id='div3'></div>
</div>
</div>
</body>
</html>


需要 jquery.js 自己引入
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: