亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript全選

original 2019-02-12 16:49:51 265
abstrait:<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>JavaScript全選</title></head><style> &nb

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>JavaScript全選</title>
</head>
<style>
   .box{width: 120px; margin: 100px auto;border: 1px solid;  border-radius: 5px;padding:5px 0px 5px 20px;}
   .box1{border-bottom:1px solid;}
    input{margin: 8px}
</style>
<body>
<div class="box">
   <div class="box1">
       <input type="checkbox" id="checkall" onclick="checkAll()"><lable for="checkall">全選</lable>
   </div>
   <div class="box2">
       <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>
</div>
<script>
   function checkAll() {
       var checkall=document.getElementById('checkall')
       var 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>
</body>
</html>

Professeur correcteur:天蓬老師Temps de correction:2019-02-12 17:00:20
Résumé du professeur:name ="item[]", 這樣寫是給后端php讀取的, 他會(huì)把它識(shí)別為數(shù)組元素, 不過是索引鍵名,如果想自定義鍵名,可以使用字符串方式,例如: name ="item['one']", name ="item['two']", 這樣寫也是可以的

Notes de version

Entrées populaires