jQuery阻止冒泡和HTML默认操作

mac2022-06-30  24

A:return false --->In event handler ,prevents default behavior and event bubbing 。          return false 在事件的处理中,可以阻止默认事件和冒泡事件。 B:event.preventDefault()---> In event handler ,prevent default event (allows bubbling) 。          event.preventDefault()在事件的处理中,可以阻止默认事件但是允许冒泡事件的发生。 C:event.stopPropagation()---> In event handler ,prevent bubbling (allows default behavior).          event.stopPropagation()在事件的处理中,可以阻止冒泡但是允许默认事件的发生。 代码如:          $('.menu li').click(function(){             $(this).find('ul').toggle();              return false;//去掉试试效果             })   //兼容代码如下: 

function stopBubble(e) { //如果提供了事件对象,则这是一个非IE浏览器 if ( e && e.stopPropagation ) //因此它支持W3C的stopPropagation()方法 e.stopPropagation(); else //否则,我们需要使用IE的方式来取消事件冒泡 window.event.cancelBubble = true; }

 

 

转载:http://www.cnblogs.com/radom/archive/2010/11/13/1876179.html

转载于:https://www.cnblogs.com/-gap/archive/2012/09/15/2686533.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)