<html>
<head>
<script type="text/javascript" src="jquery-1.5.2.min.js"></script> <script>
$(function() {
alert($(".test").find("p").size());
})
</script></head><body>
<p class="test"><p>123</p></p>
</body>
</html> 
为什么弹出的是0呢?
如果把<p>123</p>改成<span>123</span>  find("p")改成find("span")  就可以弹出1了。

解决方案 »

  1.   

    另外,这么写也是可以弹出1的:<html>
    <head>
    <script type="text/javascript" src="jquery-1.5.2.min.js"></script> <script>
    $(function() {
    alert($("#test").find("div").size());
    })
    </script></head><body>
    <div class="test">
    <div>123</div>
    </div>
    </body>
    </html> 
    是<p>标签不能嵌套吗?
      

  2.   

    p元素不能包含块级元素,代码本身已经不符合HTML标准了吧。
      

  3.   

    $(".test")这样是以p元素往下找
    $(document)
    p最好不要这样嵌套
      

  4.   

    <p class="test"><p>123</p></p>
    用法错误,
    <p>遇到<p>就结束了,会开始新的p,不会形成嵌套关系,用firebug看看页面生成的代码就清楚了。