之间的区别是什么google i/o大会的空间和>选择?
-
10-07-2019 - |
解决方案
有关:
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2.1</li>
<li>Item 2.2</li>
</ul>
</li>
<li>Item 3</li>
</ul>
例如
$("ul > li").addClass("blah");
增加了类 “等等” 为1 2和3,而:
$("ul li").addClass("blah");
添加类 “等等” 的每一个的列表元素。
我不知道你指的是与<什么?运算符。
其他提示
在CSS,>
意思是“的直接子”:只有那些直接子被选择的节点
虽然空间的意思是“的任何后代”:直接子和这些儿童的儿童可被选择
我将下注jQuery使用相同的惯例。
如前所述,一个空间将选择任何后代,而>
将只选择直接孩子。如果你想只选择孙子或曾孙,那么你可以使用这样的:
#foo > * > * > .bar
(全用类“BAR”,其是ID为“富”的元件的大的孙子元素)
看这..
$(".testit > a") //match the first <a> tag below
$(".testit a") // matches all <a> tag below
<p class="testit">
<a href="#">All the rules will match this</a>
<span>
<a href="#">second rule can only select this</a>
</span>
</p>
不隶属于 StackOverflow