复选框,全选或者全不选

复选框,全选或者全不选_第1张图片

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript" type="text/javascript">
var selectAllFlg = false;


function selectAll() {
var list = document.getElementById("waveDataListTable").getElementsByTagName("input");

for (var i = 0; i < list.length; i++) {
var ctrl = list[i];

if (ctrl.type == "checkbox") {
var s = selectAllFlg ? ctrl.checked = false : ctrl.checked = true;
}

}

selectAllFlg = !selectAllFlg;
}
</script>


<table id="waveDataListTable" width="800" border="1">
<tr>
<td width="42" height="36">No</td>
<td width="340">名称</td>
<td width="292">测试号</td>
<td width="98">选择<br />
<u>
<a href="javascript:selectAll();">(全选/取消)</a>
</u> </td>
</tr>
<tr>
<td>1</td>
<td>Vibration_01</td>
<td>channel_01</td>
<td>
<input type="checkbox" name="checkbox[0]" value="checkbox" /> </td>
</tr>
<tr>
<td>2</td>
<td>Vibration_01</td>
<td>channel_02</td>
<td><input type="checkbox" name="checkbox[1]" value="checkbox" /></td>
</tr>
<tr>
<td>3</td>
<td>Vibration_01</td>
<td>channel_03</td>
<td><input type="checkbox" name="checkbox[2]" value="checkbox" /></td>
</tr>
</table>

你可能感兴趣的:(复选框)