我有一些嵌套元素,每个元素都有一个 onclick 事件。在大多数情况下,我希望在用户单击子项时触发这两个事件(父事件和子事件都被触发 - 默认行为)。但是,至少在一种情况下,我想触发孩子的 onclick 事件(来自 javascript,而不是用户的点击),而不是父母的。如何防止它触发父事件?
我的情况是:
用户点击 A: A 的 onclick 触发。
用户点击 B: B 的 onclick 触发,A 的 onclick 也触发
手动触发 B 的点击: B 触发,A 没有(这个是问题)