简体   繁体   English

如何在 Jquery 中的 event.currentTarget 中选择/查找元素?

[英]How to select/find an element inside an event.currentTarget in Jquery?

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.我无法直接绑定到input因为单击几次后,此绑定将在 iOS3+4 上失效。 Binding to the closest ui-btn works throughout.绑定到最近的ui-btn始终有效。

Question:问题:
Is there a better/easier/faster way to do the binding than what I'm using ?有没有比我使用的更好/更容易/更快的方法来进行绑定?

You can just use this instead of e.currentTarget :您可以使用this代替e.currentTarget

$(this).find(...);

Proof that event.currentTarget and this are the same.证明event.currentTargetthis是一样的。

Also the documentation says:文档还说:

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 遍历方法是很常见的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM