您的位置:首页 > 其它

.size()的使用,点击增加更多

2011-12-17 22:41 253 查看
<!DOCTYPE html>
<html>
<head>
<style>
body { cursor:pointer; min-height: 100px; }
div { width:50px; height:30px; margin:5px;
float:left; background:blue; }
span { color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<span></span>
<div></div>

<script>
$(document.body)
.click(function() {
$(this).append( $("<div>") );
var n = $("div").size();
$("span").text("There are " + n + " divs. Click to add more.");
})
// trigger the click to start 本来只有一个,页面已载入事件就已经触发,显示2个
.click();
</script>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐