我想在单击子 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').click(函数 (e) { 一些父代码 }
子元素的函数。
$('#child_id').click(function (e) {
e.stopPropagation();
But I what to prevent parent click
SomeChildCode
}
最佳答案
使用 PreventDefault 和 stopPropagation。
$('#child_id').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
});
关于javascript - 单击子级时阻止父级单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44332410/