微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

防止点击事件影响父jquery

我是要阻止从孩子到父母的事件传播,我有一堆包含一个的li标签.

$('li a[rel=close]').live('click',function(e){
    e.stopPropagation();
    e.preventDefault();
})

但它并没有停止事件.任何建议?

解决方法

stopPropagation有关于live的问题,来自jQuery stopPropagation docs –

Since the .live() method handles events once they have propagated to
the top of the document,it is not possible to stop propagation of
live events

正如Rob W所说,你的代码可以正常使用bind,这是一个演示 – http://jsfiddle.net/TmKyT/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐