选中复选框,取消选中复选框

时间:2020-12-30 08:06:54
<html>
<head>
</head>
<body>
<table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0" width="100% "style="text-align:center;border-collapse:collapse">

<tr>
<td> 资产类型</td>
<td colspan="2">您当前选中的记录数为:<input type="text" name="jls" id="jlsid" value="0" size="6" readonly="true">
</td>
</tr>
<tr>
<td>全选<input id ="controlAll" type="checkbox" name="checkAll" value="" onclick="chk_all_checkbox()">
</td>
<td>资产类型</td>
<td>资产编号</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="1" onClick="countJls()"/></td>
<td>电能表</td>
<td> wD0804225274</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="2" onClick="countJls()"/></td>
<td>电能表</td>
<td>wD0804225273</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="3" onClick="countJls()"/></td>
<td>电流互感器 </td>
<td>w13C17372F982426548</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="4" onClick="countJls()"/></td>
<td>电流互感器 </td>
<td>w13C17372F982426562</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="5" onClick="countJls()"/></td>
<td>电流互感器 </td>
<td>w13C17372F982426537</td>
</tr>
</table>
</body>
<script>
function chk_all_checkbox(){
var checkList = document.getElementsByName("checkbox");
if(document.getElementById("controlAll").checked){
for(var i=0;i<checkList.length;i++){
checkList[i].checked = 1;
}
document.getElementById("jlsid").value=checkList.length;
}else{
for(var i=0;i<checkList.length;i++){
checkList[i].checked = 0;
}
document.getElementById("jlsid").value=0;
}
}
function countJls(){
var count = 0;
var checkList = document.getElementsByName("checkbox");
for(var i=0;i<checkList.length;i++){
if(checkList[i].checked == true){
count++;
}
}
document.getElementById("jls").value=count;
}
</script>
</html>