简体   繁体   English

jquery 多路选择器带本

[英]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.

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