????:<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>全選</title> <link rel="stylesheet" type="text/css" href=""> &
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>全選</title>
<link rel="stylesheet" type="text/css" href="">
<link rel="shortcut icon" type="image/x-icon" href="">
<style type="text/css">
.box{width: 120px;height: 250px;border: 1px solid #ccc; border-radius: 5px;padding: 5px 10px;margin: 20px auto;}
.box div {border-bottom: 1px solid #ccc;padding-bottom: 10px;margin-bottom: 8px;}
.box input{margin: 8px;}
</style>
<body>
<div class="box">
<div>
<input type="checkbox" id = "checkall" ><label for="checkall">全選</label>
</div>
<input type="checkbox" name = "item" onclick="checkitem(this)" >選項1<br>
<input type="checkbox" name = "item" onclick="checkitem(this)" >選項2<br>
<input type="checkbox" name = "item" onclick="checkitem(this)" >選項3<br>
<input type="checkbox" name = "item" onclick="checkitem(this)" >選項4<br>
<input type="checkbox" name = "item" onclick="checkitem(this)" >選項5<br>
<input type="checkbox" name = "item" onclick="checkitem(this)" >選項6<br>
</div>
<script type="text/javascript">
checkall.onclick=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;
}
}
}
function checkitem(x){
var checkall;
checkall = document.getElementById("checkall");
if(!x.checked){
if(checkall.checked){
checkall.checked = false;
}
}
}
</script>
</body>
</html>
總結(jié):在對標(biāo)簽進行操作時,在獲取一些列相同樣式的標(biāo)簽時,可以用一個對象進行獲取,獲取一個數(shù)組對象。同樣也可以在調(diào)用方法時將對象傳入,同樣可以獲取對象。
?? ???:韋小寶?? ??:2019-02-21 11:43:26
???? ??:全選這個案例不管是在網(wǎng)站的前臺還是網(wǎng)站的后臺基本上都會使用的 可想而知是多重要的 一定要好好掌握!