[英]jquery multiple selector with a this
I see, from to time, this kind of jquery selector, which I don't really understand.我时不时看到这种 jquery 选择器,我不太明白。 What does
this
do in it: this
在其中有什么作用:
$('.myClass', this).someFn();
Can someone explain to me, please?有人可以向我解释一下吗?
Thanks谢谢
That searches for child elements with a class of myClass
in the context of whatever this
is and then calls someFn();
在
this
的上下文中搜索具有myClass
的 class 的子元素,然后调用someFn();
It would give you the same results as writing $(this).find(".myClass").someFn();
它会给您与编写
$(this).find(".myClass").someFn();
相同的结果。 but is not as efficient.但效率不高。
This means that you are trying to select .myClass
inside just this
this
意味着您正在尝试在 select .myClass
里面
The "this" keyword is something that is only meaningful inside a method of an object. “this”关键字仅在 object 的方法中有意义。 It will mean something different -- or nothing at all -- depending on where you're calling this code from.
这将意味着不同的东西——或者根本没有——取决于你从哪里调用这个代码。
If you're calling it from inside an object (usually an HTML element), the object will be added to the selector that is passed to jQuery.如果您从 object(通常是 HTML 元素)内部调用它,则 object 将被添加到传递给 ZF590B4FDAC30CBE28 的选择器中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.