checkbox全选

jquery代码如下(在jquery1.10.2下验证通过):

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="Scripts/WebForms/jquery-1.10.2.min.js"></script>
<title>测试全选</title>
<script type="text/ecmascript">
$(function () {
var tbl = $("#tblTest");
tbl.empty();
var tr = "";
for (var i = 0; i < 25; i++) {
var row = 1;
if (i % 5 == 0) {
tr += "<tr>";
}
tr += "<td style=\"padding:5px;\"><input type=\"checkbox\" id=\"" + i + "\" value=\"" + i + "\" /><label for=\"" + i + "\">第" + i+1 + "个</label></td>";
if ((i + 1) / 5 == row && (i + 1) % 5 == 0) {
tr += "</tr>";
row++;
}
}
tbl.append(tr); $("#chkAll").click(function () {
if ($("#chkAll").is(":checked")) {
$("#tblTest input[type='checkbox']").prop("checked", "checked");
}
else {
$("#tblTest input[type='checkbox']").removeAttr("checked");
}
});
});
</script>
</head>
<body>
<div style="margin-left: 5px;">
<div style="padding: 6px">
<input type="checkbox" id="chkAll" /><label for="chkAll">全选</label></div>
<div>
<table id="tblTest" style="width: 100%"></table>
</div>
</div>
</body>
</html>
上一篇:Android5.0新特性:RecyclerView实现上拉加载更多


下一篇:Android5.0新特性——全新的动画(animation)