javascript $('ul', this.el) 中 "this.el" 的含义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7450224/
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
meaning of "this.el" in $('ul', this.el)
提问by user834418
I am just going through some backbone tutorials and I have a general jQuery question that I have actually been wondering for a while.
我只是在浏览一些主干教程,我有一个通用的 jQuery 问题,我实际上已经想了一段时间。
Sometimes I see calls with a second parameter in the jQuery selector, for example $('ul', this.el)
.
有时我会在 jQuery 选择器中看到带有第二个参数的调用,例如$('ul', this.el)
.
What is the purpose of this second param in the selector? And I don't really mean in context of any backbone examples, just in general what is the purpose of passing the second param in the selector and why is it always an object that is passed there? I can't find any documentation on this.
选择器中第二个参数的目的是什么?而且我的意思并不是在任何主干示例的上下文中,只是一般来说,在选择器中传递第二个参数的目的是什么,为什么它总是一个对象传递到那里?我找不到任何关于此的文档。
采纳答案by Sam Dolan
It narrows the search for a ul
tag within your view component's DOM element.
它缩小了ul
在视图组件的 DOM 元素中搜索标签的范围。
回答by user113716
The meaning is identical to:
含义与以下相同:
$(this.el).find('ul')
Internally, after a bunch of tests, jQuery figures out that it needs to flip it around to the above .find()
call, so it does, and starts over.
在内部,经过一系列测试后,jQuery 发现它需要将其翻转到上面的.find()
调用中,所以它这样做了,并重新开始。
So providing the context as the second argument is just a slower way to do a .find()
.
因此,提供上下文作为第二个参数只是执行.find()
.
// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
} else {
return this.constructor( context ).find( selector );
}
...where this.constructor
is the $
function, context
is your second argument, and selector
is your first argument.
...这里this.constructor
是$
功能,context
是你的第二个参数,selector
是你的第一个参数。