This is probably something quite to resolve, but for some reason, I can't figure it out. 解决,但是由于某些原因,我无法弄清楚。
I have the following HTML:
<li onclick="function_1();">
<input type="checkbox" onclick="function_2();">
<div onclick="function_3();">
</li>
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?
Thanks for the help!
使用stopPropagation函数
另外,您也可以从子元素onclick函数return false
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.