<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>我的页面</title>
<script type="text/javascript">
function qx(){
var qx,xx;
qx=document.getElementById('qx');
xx=document.getElementsByName("xx[]");
for(var i=0;i<xx.length;i++) {
if (qx.checked){
xx[i].checked=true;
}else{
xx[i].checked=false;
}
}
}
</script>
</head>
<body>
<div>
<div><input type="checkbox" id="qx" onclick="qx()"><label for="qx">全选</label>
</div><br>
<input type="checkbox" name="xx[]">选项1 <br>
<input type="checkbox" name="xx[]">选项2 <br>
<input type="checkbox" name="xx[]">选项3 <br>
<input type="checkbox" name="xx[]">选项4 <br>
<input type="checkbox" name="xx[]">选项5 <br>
</div>
</body>
</html>
如果选项是数据库查询出来的遍历循环数值,选择之后进行操作体验度更高