元素中的Javascript/jQuery Click元素 [英] Javascript/jQuery Click Element within Element

查看:109
本文介绍了元素中的Javascript/jQuery Click元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很容易解决,但由于某些原因,我无法弄清楚.

This is probably something quite easy to resolve, but for some reason, I can't figure it out.

我有以下HTML:

<li onclick="function_1();">
  <input type="checkbox" onclick="function_2();">
  <div onclick="function_3();">
</li>

我的问题是:每当我单击子元素之一(复选框或div)时,它也会从<li>-> function_1()执行该功能.

My issue is: Whenever I click one of the child elements (either the checkbox or div), it also carries out the function from the <li> --> function_1().

如何防止单击子元素时调用父元素函数?实现此目标的最佳方法是什么?

How can I prevent the parent element function from being called when child element is being clicked? What is the best way to achieve this?

感谢您的帮助!

推荐答案

使用 stopPropagation 函数

这篇关于元素中的Javascript/jQuery Click元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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