子行为不会触发父级jquery [英] child action doesn't trigger parent jquery

查看:83
本文介绍了子行为不会触发父级jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对父div中的< a> ,它会在点击时执行特定的操作。我怎么做才能让用户点击每个< a href =xxxx> 时,用户只会链接到其他页面,父功能不会触发?

解决方案

停止点击 ,如下所示:

  $(a)。click(function(e){
e.stopPropagation( );
});

请参阅 event.stopPagagation $ b

I have couple <a> within a parent div which will perform a specific action when clicked. How can I make it so that when user clicks each <a href="xxxx">, user will only get linked to other pages and the parent function will not be triggered?

Stop the click event from bubbling up to the parent, like so:

$("a").click(function(e) {
    e.stopPropagation();
});

See event.stopPropagation

Demo.

这篇关于子行为不会触发父级jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆