jQuery Length属性

时间:2023-03-08 16:19:27

Length属性

属性用于返回当前jQuery对象的元素个数。

语法

jQueryObject.length

返回值

Number类型 返回该jQuery对象封装的DOM元素的个数。

实例说明

代码

 1 <!DOCTYPE html>
2 <html lang="zh-CN">
3 <head lang="en">
4 <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
5
6 </head>
7 <body>
8 <div></div>
9 <div></div>
10 <div>
11 <ul>
12 <li>one</li>
13 <li>two</li>
14 <li>three</li>
15 </ul>
16 </div>
17 <script>
18 var j_li = $("div");
19 document.writeln( j_li.length );
20 var j_p = $("p");
21 document.writeln( j_p.length );//无<p>标签所以结果为0
22 </script>
23 </body>
24 </html>

运行结果

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAACGCAIAAADVWBZRAAADz0lEQVR4nO2dMW6DMBhGPfYQHXoDlo49Sr3nGF19li6WeogOWZEy9hgZ3YGADcFAo5SYj/eWJoDSVE8/NvD5rwkgjXn0F4D/BcHiIFgcBIuDYHEQLA6CxUGwOAgWB8HiIFgcBIuDYHEQLA6CxUGwOAgWB8HiIFgcBIuDYHEQLM6qgk+n0/f39/l8XvOX7pz1BL+/vxtjjDHPz8/H43H6YG/NhcrVIYQQalcZY6xvfiY7kr3GGGOs/8c/YnusJPjz89MkvL6+ThzsbdRUu6p77W30mm6vXZXY9ranfu+sJPjj4yMV/PT0lD20ryt9721SnvFNUr0U8RUrCf76+koNvL29ZQ/19vrs2xjLCO5thgHrjcGHw6Gx+/LycjqdssfdUsGclLOsOov++fk5Ho+zs+i0hgdj8JjgULsqKfraOeo5Uuh1cJxFpxa7De3uTms83lDNPQoVDPcCweIgWBwEi4NgcRAsDoLFQbA4CBYHweIgWJxyBXvHTeU7UGomi2eAd6LATFbyZCg+T7pstL55UTnfPF2KD/15mDRKiZmsEMYquHZVG+xoAwCuCwKMZrgglJjJahg5RV8Md4/3L37zCRAIJWayGsY0NaXrnbWV9Wn9ZjJcEErMZDWM1qG3lXPO1b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