jQuery 添加元素
append()
prepend()
after()
before()
$("table").append("<tr><th>商品编号</th><th>商品名称</th></tr>");
var row3 = $("tr").after("<tr><td>3</td><td>罗技鼠标</td></tr>");
var row2 = $("tr:last").before("<tr><td>2</td><td>dell台式机</td></tr>");
$("<tr><td>4</td><td>漫步者音箱</td></tr>").appendTo($("table"));
$("<tr><td>1</td><td>ThinkPad笔记本</td></tr>").insertAfter($("tr:first"));
});
jQuery 尺寸
width()
height()
outerWidth()
outerHeight()
<script>
$(function(){
console.log($("#box1").width())
console.log($("#box1").height())
console.log($("div").outerWidth())
console.log($("div").outerHeight())
//$("#box").width(200);
//$("#box").height(200);
})
</script>
</head>
<body>
<div id="box1" style="width: 200px;height: 100px;border: 6px solid #ff0000;">
box1
</div>
<div id="box2" style="width: 150px;height: 150px;border: 5px solid #ff0000;">
box2
</div>
</body>
jQuery 过滤
first()
last()
eq()
filter()
not()
<script>
$(function(){
console.log($("div").first().attr("id"));
console.log($("div").last().attr("id"));
console.log($("div").eq(0).attr("id"));
console.log($("div").eq(1).attr("id"));
console.log($("div").not(1).attr("id"));
console.log($("div").filter("#box1").attr("id"));
console.log($("div").filter(".box1").attr("id"));
})
</script>
</head>
<body>
<div id="box1" class="box1" style="width: 200px;height: 100px;border: 6px solid #ff0000;">
box1
</div>
<div id="box2" style="width: 150px;height: 150px;border: 5px solid #ff0000;">
box2
</div>
</body>