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

JS全選案例和總結(jié)

original 2018-12-26 17:48:46 247
abstrait:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml&quo

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>全選</title>

<style type="text/css">

.box{

width: 120px;

height: 250px;

border: 1px solid #CCC;

border-radius: 5px;

padding-top: 5px;

padding-right: 10px;

padding-bottom: 0px;

padding-left: 0px;

margin-top: 20px;

margin-right: auto;

margin-bottom: auto;

margin-left: auto;

}


.box div{

border-bottom-style: solid;

border-bottom-width: 1px;

border-bottom-color: #F00;

padding-bottom: 10px;

}


.box input{

margin: 8px;

}

</style>


<script type="text/javascript">

  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>


<!--總結(jié)

for 循環(huán)語句

如果一遍又一遍的運行相同的代碼,并且每次的值都不同,可以用for語句


for( var i=0;i<item.length;i++){

item[i].checked=ture

}


條件語句

if..else  當條件為ture時執(zhí)行代碼,當條件為false時執(zhí)行其他代碼

if(checkall.checked){item[i].checked=true}

else{item[i].checked=false}


document.getElementById('') 

document.getElementsName("")

->




Professeur correcteur:滅絕師太Temps de correction:2018-12-27 09:26:28
Résumé du professeur:完成的不錯!繼續(xù)加油喲!有案例有分析是個很好的習(xí)慣!

Notes de version

Entrées populaires