夺命雷公狗jquery---26事件冒泡介绍和阻止方法
2015-10-27 15:14
621 查看
什么是事件冒泡可以通过以下代码即可知晓
阻止的方法其实也很简单,只要加上event 和event.stopPropagetion()即可阻止事件冒泡了,如下代码所示
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> #div1{ width:400px; height:400px; background-color:red; } #div2{ width:300px; height:300px; background-color:blue; } #div3{ width:200px; height:200px; background-color:green; } </style> <script src="js/jquery.js"></script> <script> $(function(){ $('#div1').bind('click',function(){ alert('div1'); }); $('#div2').bind('click',function(){ alert('div2'); }); $('#div3').bind('click',function(){ alert('div3'); }); }) </script> </head> <body> <div id="div1"> <div id="div2"> <div id="div3"></div> </div> </div> </body> </html>
阻止的方法其实也很简单,只要加上event 和event.stopPropagetion()即可阻止事件冒泡了,如下代码所示
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> #div1{ width:400px; height:400px; background-color:red; } #div2{ width:300px; height:300px; background-color:blue; } #div3{ width:200px; height:200px; background-color:green; } </style> <script src="js/jquery.js"></script> <script> $(function(){ $('#div1').bind('click',function(){ alert('div1'); }); $('#div2').bind('click',function(event){ alert('div2'); event.stopPropagation(); }); $('#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 Validation Engine表单验证为false
- jQuery单击按钮,按钮变,内容展开
- jQuery结合elevateZoom演示多种放大镜效果
- JSP+JQuery Ajax+Servlet 实现轮询方式消息提示功能
- jQuery的选择器中的通配符[id^='code']
- 夺命雷公狗jquery---25事件绑定中的this指向
- 基于Jquery ajax技术实现间隔N秒向某页面传值
- jquery "缺少标识符、字符串或数字"
- jquery 字符串转数字
- javascript基础之十三(Jquery基础)
- jQuery中读取json文件示例代码
- jquery中判断是否按下回车键
- 三、jQuery--jQuery基础--jQuery基础课程--第4章 jQuery表单选择器
- ie下jquery.getJSON的缓存问题的处理方法
- this $this $(this)
- Jquery插件 防刷新倒计时 “点击获取验证码后60秒内禁止重新获取
- jQuery mouseover与mouseenter的区别
- jquery ajax的async属性的理解
- 基于jQuery的软键盘
- Jquery判断某个标签 Id是否存在