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í)慣!