javascript 全选

Original 2019-02-27 15:21:33 193
abstract:<!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; //当全选被选中时,下面的勾选框选中
}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[]">选项1<br/>
   <input type="checkbox" name ="item[]">选项2<br/>
   <input type="checkbox" name ="item[]">选项3<br/>
   <input type="checkbox" name ="item[]">选项4<br/>
   <input type="checkbox" name ="item[]">选项5<br/>
   <input type="checkbox" name ="item[]">选项6<br/>

</div>
</body>
</html>

<!-- 疑问,怎么调整,让下面的全部选中时上面的全选也选中?  -->

Correcting teacher:查无此人Correction time:2019-02-27 15:58:45
Teacher's summary:完成的不错。有问题可以提交工单,在这里回答你,你无法追问。 全选需要循环,你可以百度下,做不好可以在提交工单。

Release Notes

Popular Entries