abstract:<!doctype html><html><head><meta charset="UTF-8"><title>全选</title><style>#box{width: 130px;height: 280px;border:1px solid #000;padding: 8px 10px;mar
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>全选</title>
<style>
#box{width: 130px;height: 280px;border:1px solid #000;padding: 8px 10px;margin: 20px auto;}
#box div{border-bottom: 1px solid #ccc;padding: 5px 5px;margin: 5px;}
#box input{margin: 6px;}
</style>
<script>
function checkall(){
var checkall,item;
checkall=document.getElementById('checkall');
item=document.getElementsByName("item[]");
for (var i = 0;i<item.length ;i++) {
if(checkall.checked){
item[i].checked=true;
}else{
item[i].checked=false;
}
}
}
</script>
</head>
<body>
<div id="box">
<div >
<input type="checkbox" id="checkall" onclick="checkall()">
<label for="checkall">全选</label>
</div>
<input type="checkbox" name="item[]">web前端 <br>
<input type="checkbox" name="item[]">web后台<br>
<input type="checkbox" name="item[]">JavaScript <br>
<input type="checkbox" name="item[]">PHP脚本 <br>
<input type="checkbox" name="item[]">MySQL数据库 <br>
<input type="checkbox" name="item[]">Jquery <br>
<input type="checkbox" name="item[]">BootStrop <br>
</div>
</body>
</html>
Correcting teacher:灭绝师太Correction time:2019-03-08 09:35:40
Teacher's summary:全选案例后期使用场景很多 , 要掌握原理 !