当前位置: 代码迷 >> JavaScript >> jquery的closest()方法解决思路
  详细解决方案

jquery的closest()方法解决思路

热度:43   发布时间:2012-04-11 17:42:33.0
jquery的closest()方法
JScript code

<head>
    <style type="text/css">

    </style>

    <script type="text/javascript" src="jquery-1.5.2.min.js"></script>

    <script>
        $(function() {
            alert($("li:first").closest(["ul", "body"]));
        })
    </script>

</head>

<body>
        <ul><li></li><li></li></ul>
</body>



JScript code

<head>
    <style type="text/css">

    </style>

    <script type="text/javascript" src="jquery-1.5.2.min.js"></script>

    <script>
        $(function() {
            alert($("li:first").closest(["ul", "body"]).size());
        })
    </script>
</head>

<body>
        <ul><li></li><li></li></ul>
</body>



第一段代码弹出是Object,第二段代码就报错,说没这个函数。
难道closest()方法返回的不是Jquery包装集吗?不能使用.size()??

谢谢!

------解决方案--------------------
alert($("li:first").closest("ul","body").size());
没有中括号
  相关解决方案