サマリー:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>全選</title> <style> h3{width: 100%;text
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>全選</title>
<style>
h3{width: 100%;text-align: center;color: red;}
.buy{width: 300px;height: 300px; border: 1px solid #ccc;margin: 0 auto;}
.buy div{height:30px;padding:10px 0px;border-bottom: 1px solid #ddd;line-height: 30px;}
.buy input{margin: 10px;}
</style>
<script>
function cheackAll(){
var cheackall = document.getElementById('cheackall')
var item = document.getElementsByName('item[]')
for(var i=0;i<item.length;i++){
if(cheackall.checked){
item[i].checked=true;
}else{
item[i].checked=false;
}
}
}
</script>
</head>
<body>
<h3>購物車</h3>
<div>
<div>
<input type="checkbox" id="cheackall" onclick="cheackAll()"><label for="cheackall">全選</label>
</div>
<input type="checkbox" name="item[]">手機(jī)<br>
<input type="checkbox" name="item[]">電腦<br>
<input type="checkbox" name="item[]">電視<br>
<input type="checkbox" name="item[]">冰箱<br>
<input type="checkbox" name="item[]">洗衣機(jī)<br>
<input type="checkbox" name="item[]">電磁爐<br>
</div>
</body>
</html>
添削の先生:滅絕師太添削時(shí)間:2019-02-16 15:55:16
先生のまとめ:全選案例在后期使用場(chǎng)景較多,要好好掌握,理解每一條語句的意思