用逗号分隔的选择器列表? [英] Comma separated list of selectors?
问题描述
此刻我正在重构一些代码,并且遇到了一个选择器:
I'm refactoring some code at the moment and have come across a selector:
jQuery("tr","#ctl00_MainContent_MyUserControl").each(function(i,row) { ... }
看起来它是从页面上的用户控件中选择<tr>
的(忽略实例完全命名的事实!),但这不是我熟悉的语法,因此无法在其中找到任何内容文档.我希望它会写成:
It looks like it's selecting <tr>
's from the user control on the page (ignore the fact that the instance is fully named!) but it's not a syntax I'm familiar with and can't find anything in the documentation. I'd expect it to be written:
$("#ctl00_MainContent_MyUserControl tr").each(function(i,row) { ... }
有人可以告诉我我在这里是否有所不同(微妙或其他)?
Can anyone tell me if there's a difference (subtle or otherwise) that I'm missing here??
推荐答案
此选择器选择所有
This selector selects all tr
elements inside an element with id ctl00_MainContent_MyUserControl
. It is exactly the same as your second example.
第二个参数为第一个参数提供上下文.此语法有更好的用例,例如:
The second parameter provides a context for the first parameter. There are better use cases for this syntax, for example:
function(el) {
$('tr', el).each(...);
}
el
是页面上的某些元素.在这种情况下,您不能使用第二种语法形式.
Where el
is some element on your page. In this case, you can't use the second syntax form.
这篇关于用逗号分隔的选择器列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!