全选操作和取消全选操作
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function selectAll(obj){
var obj = document.getElementsByName("checkbox");
if(null!=obj){
alert("全选操作!!!");
for (var i = 0; i < obj.length; i++) {
obj[i].checked = "checked";
}
}
}
function unselectAll(obj){
var obj = document.getElementsByName("checkbox");
if(null!=obj){
alert("取消全选操作!!!");
for (var i = 0; i < obj.length; i++) {
obj[i].checked = "";
}
}
}
</script>
</head>
<body>
<p>全选和不全选的问题</p>
<table border="1" style="position: center;">
<tr>
<td>读书</td>
<td><input type="checkbox" name="checkbox" value="1"/></td>
</tr>
<tr>
<td>写字</td>
<td><input type="checkbox" name="checkbox" value="2"/></td>
</tr>
<tr>
<td>运动</td>
<td><input type="checkbox" name="checkbox" value="3"/></td>
</tr>
<tr>
<td colspan="2">
<button type="button" onclick="selectAll('checkbox')">全选操作</button>
<button type="button" onclick="unselectAll('checkbox')">取消全选</button>
</td>
</tr>
</table>
</body>
</html>