http://jsfiddle.net/sushilbharwani/zWgNX/我试图理解>选择器我想知道为什么小提琴给出的大小为4. 2是我想到的.3可能是可能的,但为什么4.
HTML:
<div class="ban_hdr">
<p>
Which of the following are correct? abc abc
<p>Test this code</p>
</p>
<p>Which of the following are correct? pqr pqr</p>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
alert($('div.ban_hdr > p').size());
Run Code Online (Sandbox Code Playgroud)
我在Chrome的开发者工具中提取了源代码,至少谷歌Chrome如何解释你的来源:
<div class="ban_hdr">
<p>
Which of the following are correct? abc abc
</p>
<p>Test this code</p>
<p></p>
<p>Which of the following are correct? pqr pqr</p>
</div>
Run Code Online (Sandbox Code Playgroud)
一个<p>标签不能嵌套在一个<p>标签.所以,这显然是Chrome对你的意思的最好诠释.去搞清楚.当您使用无效代码时,期望无意义的结果.