HTML:
<td><input type="checkbox" name="checkAll" id="checkAll" onclick="swapCheck()" /></td>
JS:
<td><input type="checkbox" name="checkId" id="checkId" value="' + this.SId + '" onchange="Getcheckbox()"/></td>
方法:
//checkbox 全选/取消全选
var isCheckAll = false;
function swapCheck() {
if (isCheckAll) {
$("input[type='checkbox']").each(function () {
this.checked = false;
Getcheckbox();
});
isCheckAll = false;
} else {
$("input[type='checkbox']").each(function () {
this.checked = true;
Getcheckbox();
});
isCheckAll = true;
}
}
function Getcheckbox() {
var str = document.getElementsByName("checkId");
var objarray = str.length;
var chestr = "";
for (i = 0; i < objarray; i++) {
if (str[i].checked == true) {
chestr += str[i].value + ":";
}
}
document.getElementById("checkValue").value = chestr;
}