阻止事件的冒泡
2015-07-28 23:01
711 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-1.8.0.min.js"></script>
</head>
<body>
<div style="width: 300px;height: 300px;background-color: aqua">
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
/*点击div时,body绑定的事件也被执行,*/
$("body").bind("click",bodyHandler);
$("div").bind("click",divHandler);
$("div").bind("click",divHandler2);
})
function divHandler(event){
conlog(event)
event.stopPropagation();/*阻止父级body的事件发生,*/
//event.stopImmediatePropagation();/*阻止其他所有的事件发生*/
}
function bodyHandler(event){
console.log("hello");
conlog(event)
}
function divHandler2(event){
console.log("hello");
conlog(event)
}
function conlog(event){
console.log(event);
}
</script>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-1.8.0.min.js"></script>
</head>
<body>
<div style="width: 300px;height: 300px;background-color: aqua">
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
</ul>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
/*点击div时,body绑定的事件也被执行,*/
$("body").bind("click",bodyHandler);
$("div").bind("click",divHandler);
$("div").bind("click",divHandler2);
})
function divHandler(event){
conlog(event)
event.stopPropagation();/*阻止父级body的事件发生,*/
//event.stopImmediatePropagation();/*阻止其他所有的事件发生*/
}
function bodyHandler(event){
console.log("hello");
conlog(event)
}
function divHandler2(event){
console.log("hello");
conlog(event)
}
function conlog(event){
console.log(event);
}
</script>
</html>
相关文章推荐
- jQuery中的常用事件总结
- C#实现WinForm捕获最小化事件的方法
- c#事件使用示例详解
- C#中的事件介绍
- C#实现自定义双击事件
- extjs 为某个事件设置拦截器
- jQuery阻止同类型事件小结
- jQuery bind事件使用详解
- C#中委托和事件的区别实例解析
- SQLSERVER中得到执行计划的两种方式
- C#中事件的动态调用实现方法
- ASP.NET中实现定制自己的委托和事件参数类
- C#处理Paint事件的方法
- javascript下利用for( in )语句 获得所有事件名称的代码
- 关于JavaScript与HTML的交互事件
- 修改正确的asp冒泡排序
- JavaScript 学习笔记(十六) js事件
- JQuery实现表格动态增加行并对新行添加事件
- WinForm实现移除控件某个事件的方法
- C#事件用法实例浅析