我有类似以下内容:
<div onclick="doSomething()">
Content...
<div onclick="doSomethingElse()">
</div>
</div>
当doSomethingElse()
被调用时,我也不想doSomething()
被调用。
在网上搜索,我找到了对event.stopPropagation()
and的引用event.cancelBubble()
,这可以防止事件冒泡到父元素。
两个问题:
如何从中获取事件对象
doSomethingElse()
?是否有必要同时使用
event.stopPropagation()
andevent.cancelBubble()
,或者业界已经为此制定了标准?