jquery api .length

来源:互联网 发布:淘宝天猫电商仓储外包 编辑:程序博客网 时间:2024/05/31 11:04

.length

描述: 在jQuery对象中元素的数量。

目前匹配的元素数量。.size()方法将返回相同的数字。



<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><script src="jquery-1.10.2.js"></script><style>body{ cursor:pointer;}div { width:50px; height:30px; margin:5px; float:left; background:#0F0; }  span { color:red; }</style></head><body><span></span><div></div><script>$(document.body).click(function(){$(document.body).append($("<div>"));var n = $("div").length;$("span").text("There are " + n + " divs." + "Click to add more.");}).trigger('click');</script></body></html>

效果图:


0 0