简体   繁体   English

子操作不会触发父级jQuery

[英]child action doesn't trigger parent jquery

I have couple <a> within a parent div which will perform a specific action when clicked. 我在父div中有一对<a> ,当单击时将执行特定的操作。 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? 如何使用户单击每个<a href="xxxx"> ,用户只能链接到其他页面,而不会触发父函数?

Stop the click event from bubbling up to the parent, like so: 阻止click事件冒泡到父事件,如下所示:

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

See event.stopPropagation 请参阅event.stopPropagation

Demo. 演示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM