开发者

jquery cross browser solution

开发者 https://www.devze.com 2022-12-28 15:02 出处:网络
What is the jQuery equivalent to the following: function stopEvent(evt)开发者_运维技巧 { if (window.event) window.event.cancelBubble = true;

What is the jQuery equivalent to the following:

function stopEvent(evt)开发者_运维技巧 {
if (window.event) window.event.cancelBubble = true;
else evt.stopPropagation();
}


The jQuery Event object implements a stopPropagation method which is a cross-browser way to prevent events from bubbling up the DOM tree. Example:

// when an anchor with id of someElement gets clicked
$("#someElement").click(function(e) {
    e.stopPropagation();
});

Bear in mind, return false has the same effect as calling both e.preventDefault() and e.stopPropagation().

0

精彩评论

暂无评论...
验证码 换一张
取 消