```<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>复选框选中按钮</title>
<style>
tr, td {
text-align: center;
}
</style>
</head>
<body>
<div align="center">
<table border="1px" cellspacing="0">
<tr>
<td><input type="checkbox" id="chkall" onclick="chk_all()">全选 <br></td>
<td>产品名称</td>
<td>价格(元)</td>
<td>数量</td>
</tr>
<tr>
<td><input type="checkbox" name="chk" onclick="chk()"> <br></td>
<td>刘亦菲时尚芭莎杂志</td>
<td>25</td>
<td>6</td>
</tr>
<tr>
<td><input type="checkbox" name="chk" onclick="chk()"> <br></td>
<td>刘亦菲明信片</td>
<td>20</td>
<td>7</td>
</tr>
<tr>
<td><input type="checkbox" name="chk" onclick="chk()"> <br></td>
<td>刘亦菲唱片</td>
<td>52</td>
<td>8</td>
</tr>
</table>
<button id="del" onclick="chk_no()">删除选中的产品(全不选)</button>
<button id="unchk" onclick="unchk()">反选</button>
</div>
<script>
function chk_all() {
var status = document.getElementById("chkall").checked;
var arrChk = document.getElementsByName("chk");
if (status) {
for (var i = 0; i < arrChk.length; i++) {
arrChk[i].checked = true;
}
} else {
for (var i = 0; i < arrChk.length; i++) {
arrChk[i].checked = false;
}
}
}
function chk_no() {
var arrChk = document.getElementsByName("chk");
for (var i = 0; i < arrChk.length; i++) {
arrChk[i].checked = false;
}
document.getElementById("chkall").checked = false;
}
function unchk() {
var arrChk = document.getElementsByName("chk");
var times =0;
for (var i = 0; i < arrChk.length; i++) {
if (arrChk[i].checked) {
arrChk[i].checked = false;
} else {
arrChk[i].checked = true;
times++;
}
if(times==arrChk.length){
document.getElementById("chkall").checked=true;
}else {
document.getElementById("chkall").checked=false;
}
}
}
function chk() {
var arrChk = document.getElementsByName("chk");
var times = 0;
for (var i = 0; i < arrChk.length; i++) {
if (arrChk[i].checked) {
times++;
}
}
if (times == arrChk.length) {
document.getElementById("chkall").checked = true;
} else {
document.getElementById("chkall").checked = false;
}
if (times == 0) {
document.getElementById("chkall").checked = false;
}
}
</script>
</body>
</html>