更新时间:2022-05-13 01:08:09
您可以使用 evt.currentTarget
来代替:
You could use evt.currentTarget
instead:
在事件冒泡阶段中的当前DOM元素。
The current DOM element within the event bubbling phase.
演示: http://jsfiddle.net/ambiguous/UgA5M/
或者你可以使用 $容器= $(evt.target).closest('。someContainer')
,而不必担心嵌套。
Or you could use $container = $(evt.target).closest('.someContainer')
and not worry about the nesting.
演示: http://jsfiddle.net/ambiguous/B49LG/
哪种方法您使用取决于您的具体情况。如果你有某种形式的控制click处理,那么最接近
可能更有意义;如果你真的想你已经绑定你的点击处理程序的元素(或认为你有,这是所有基于代表
毕竟),然后使用 currentTarget当前
。
Which approach you use depends on your specific situation. If you have a click handler on a control of some sort, then closest
might make more sense; if you really want the element that you've bound your click handler to (or think you have, this is all based on delegate
after all), then use currentTarget
.