摘要:<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/cs
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box{width:150px;height: 350px;border: solid 1px #ccc;margin:30px auto}
.box>div{border-bottom: 1px dashed #ccc;height: 30px;line-height: 30px;}
.box>input{margin:15px 0 10px 5px;}
</style>
<script type="text/javascript">
function check(){
var all=document.getElementById('checkall');
var item=document.getElementsByName('item[]');
for(var i=0;i<item.length;i++){
if(all.checked){
item[i].checked=true
}else{
item[i].checked=false
}
}
}
</script>
</head>
<body>
<div class="box">
<div>
<input type="checkbox" id="checkall" onclick="check()"/>全選
</div>
<input type="checkbox" name="item[]"/>西安<br/>
<input type="checkbox" name="item[]"/>北京<br/>
<input type="checkbox" name="item[]"/>青島<br/>
<input type="checkbox" name="item[]"/>深圳<br/>
<input type="checkbox" name="item[]"/>廣州<br/>
<input type="checkbox" name="item[]"/>上海<br/>
</div>
</body>
</html>
對(duì)于js的基礎(chǔ)操作有了更清晰的認(rèn)識(shí)
批改老師:滅絕師太批改時(shí)間:2019-01-06 12:36:16
老師總結(jié):全選案例是后期應(yīng)用中比較多的案例之一了需要好好掌握,必要的位置敲上備注