您现在的位置是:首页 > 电脑技术查询 > web开发

jquery的closest()方法解决思路

编辑:chaxungu时间:2022-10-02 23:16:01分类:web开发

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());
没有中括号