javascript 如何在 Jquery 中的 event.currentTarget 中选择/查找元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13378051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to select/find an element inside an event.currentTarget in Jquery?
提问by frequent
I'm using this:
我正在使用这个:
$('.sizeChart').on('vclick', '.entry .ui-btn', function(e){
console.log( e )
console.log( e.currentTarget )
console.log( $( e.currentTarget )
console.log( $( e.currentTarget ).find('input.qtyInput') )
var qty = $( e.currentTarget ).find('input.qtyInput');
// do something
});
Which works, but $( e.currentTarget ).find(...)
seems awkward to me.
哪个有效,但$( e.currentTarget ).find(...)
对我来说似乎很尴尬。
I can't bind directly to the input
because this binding will go dead on iOS3+4 after a couple of clicks. Binding to the closest ui-btn
works throughout.
我无法直接绑定到 ,input
因为单击几次后,此绑定将在 iOS3+4 上失效。ui-btn
始终绑定到最接近的作品。
Question:
Is there a better/easier/faster way to do the binding than what I'm using ?
问题:
是否有比我使用的更好/更容易/更快的绑定方式?
回答by Felix Kling
You can just use this
instead of e.currentTarget
:
您可以使用this
代替e.currentTarget
:
$(this).find(...);
Proof that event.currentTarget
and this
are the same.
证明event.currentTarget
和this
是一样的。
Also the documentationsays:
另外,文件说:
This property will typically be equal to the
this
of the function.
此属性通常等于
this
函数的 。
That's about it. It is pretty common to pass a DOM element directly to jQuery and use DOM traversal methods on it.
就是这样。将 DOM 元素直接传递给 jQuery 并在其上使用 DOM 遍历方法是很常见的。