????:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>全選</title> <style> .box{ width:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>全選</title>
<style>
.box{
width:120px;
height:250px;
border:1px solid #000;
border-radius: 5px;
padding: 5px 10px;
margin:20px auto;
}
.box div{
border-bottom: 1px solid #000;
padding-bottom: 10px;
margin-bottom: 8px;
}
.box input{
margin: 8px;
}
</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; //當(dāng)全選被選中時(shí),下面的勾選框選中
}else{
item[i].checked = false;//反之
}
}
}
</script>
</head>
<body>
<div class="box">
<div>
<input type="checkbox" id ="checkall" onclick="checkAll();"><label for="checkall">全選</label>
</div>
<input type="checkbox" name ="item[]">選項(xiàng)1<br/>
<input type="checkbox" name ="item[]">選項(xiàng)2<br/>
<input type="checkbox" name ="item[]">選項(xiàng)3<br/>
<input type="checkbox" name ="item[]">選項(xiàng)4<br/>
<input type="checkbox" name ="item[]">選項(xiàng)5<br/>
<input type="checkbox" name ="item[]">選項(xiàng)6<br/>
</div>
</body>
</html>
<!-- 疑問,怎么調(diào)整,讓下面的全部選中時(shí)上面的全選也選中? -->
?? ???:查無此人?? ??:2019-02-27 15:58:45
???? ??:完成的不錯(cuò)。有問題可以提交工單,在這里回答你,你無法追問。 全選需要循環(huán),你可以百度下,做不好可以在提交工單。