返回值:Numberlength
示例:
计算 div 数目,点击后增加还会增加。
<!DOCTYPE html>
<html>
<head>
<style>
body { cursor:pointer; }
div { width:50px; height:30px; margin:5px; float:left;
background:green; }
span { color:red; }
</style>
<script src="jquery.min.js"></script>
</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'); // trigger the click to start
</script>
</body>
</html>