且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

骨干查看活动得到适当的目标

更新时间: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.