我想防止父母点击时,我点击儿童SPAN。 我试图防止父母点击时点击儿童
e.stopPropagation
and thi way
if (!e) e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
我有HTML这样的:
<label for="parent_id"> Some text
<span id="child_id">Click child</span>
</label>
<input id="parent_id" />
的父元素功能
$( '#PARENT_ID')点击(函数(E){ SomeParentCode }
。子元素函数
$('#child_id').click(function (e) {
e.stopPropagation();
But I what to prevent parent click
SomeChildCode
}
请格式化您的问题。如果您想为代码添加注释,请使用注释标记,即'/ * * /'或'//',以便语法突出显示正常工作。 – nem035
我们还想在您的问题中[mcve] – j08691
[父项事件,点击子项(事件冒泡)]的可能重复项(https://stackoverflow.com/questions/27275279/event-on-parent-click-孩子事件冒泡) – Michelangelo