谁知道为什么这在世界上不起作用:
$( "p p" ).each(function() {
$(this).css("color", "green");
});
以及“p > p”,或任何带有嵌套段落元素的东西。虽然可以使用 div 和其他元素
例如检查这个:
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
alert('length='+$('p p').length); // 0
</script>
<div style="border:1px solid;">
<p>The first paragraph in div.</p>
<p>The second paragraph in div (and the 2nd child in this div).</p>
<p>
<span>Span within p (WILL BE fount as "p > span")</span>
<p>P within p (1).</p>
<span>Span within p (will NOT be fount as "p > span")</span>
<p>P within p (2).</p>
</p>
</div>
<p>
<span>Span within p (WILL BE fount as "p > span")</span>
<p>P within p (1).</p>
<span>Span within p (will NOT be fount as "p > span")</span>