(1)原生js实现checkbox全选
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="box" style="width:80px;">
<p><label for="all">全选<input type="checkbox" id="all"></label></p>
<p>西红柿<input type="checkbox" name="vegetable"></p>
<p>黄瓜<input type="checkbox" name="vegetable"></p>
<p>茄子<input type="checkbox" name="vegetable"></p>
</div>
<script>
var all = document.getElementById('all');
all.addEventListener("click",function(){
var opts = document.getElementsByName('vegetable');
for(var i = 0;i < opts.length;i++){
opts[i].checked = this.checked;
}
},false)
</script>
</body>
</html>