Jquery 点击事件渗透问题

发布于 2024-12-23 09:47:36 字数 105 浏览 3 评论 0原文

我有一个 div,它绑定了一个点击事件。我想在该 div 中放置一个图标,该图标有自己的点击事件。当我单击图标时,它会触发图标事件,然后触发 div 的单击事件。如何防止 div 的点击事件触发?

I have a div that has a click event tied to it. I want to put an icon in that div that has it's own click event tied to it. When I click the icon, it fires the icon event and then fires the div's click event. How can I prevent the div's click event from firing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆兒滾 2024-12-30 09:47:36

您可以使用 jQuery 的 event.stopPropagation()

$('.element').click(function(e)) {
  // Do some processing

  e.stopPropagation();
}

You can use jQuery's event.stopPropagation():

$('.element').click(function(e)) {
  // Do some processing

  e.stopPropagation();
}
三五鸿雁 2024-12-30 09:47:36

在图标的点击处理程序上停止传播

$(".myIcon").click(function (e) {
    e.stopPropagation();
    // do stuff
});

Stop the propagation on the icon's click handler:

$(".myIcon").click(function (e) {
    e.stopPropagation();
    // do stuff
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文