开发者

jquery cross browser solution

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜