表单的取消和全选
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class=" wrop">
<table>
<thead>
<tr>
<th>
<input type="checkbox" id="all_cheack">
</th>
<th>
标题1
</th>
<th>
标题1
</th>
</tr>
</thead>
<tbody>
<tr>
<td> <input type="checkbox" class="a_cheack"> </td>
<td>手机2</td>
<td>手机3</td>
</tr>
<tr>
<td> <input type="checkbox" class="a_cheack"> </td>
<td>手机2</td>
<td>手机3</td>
</tr>
<tr>
<td> <input type="checkbox" class="a_cheack"> </td>
<td>手机2</td>
<td>手机3</td>
</tr>
</tbody>
</table>
</div>
</body>
<script>
var inp= document.querySelector("#all_cheack")
var a_inp=document.querySelector("tbody").querySelectorAll(".a_cheack")
inp.onclick=function (params) {
for (let index = 0; index < a_inp.length; index++) {
a_inp[index].checked=this.checked
}
}
for (let i = 0; i < a_inp.length; i++) {
a_inp[i].onclick=function () {
var flag=true
for (let i = 0; i < a_inp.length; i++) {
if( !a_inp[i].checked){
flag=false
console.log("inp.checked1",flag);
}
}
inp.checked=flag
console.log("inp.checked",inp.checked);
}
}
</script>
</html>