摘要:<!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>
对于js的基础操作有了更清晰的认识
批改老师:灭绝师太批改时间:2019-01-06 12:36:16
老师总结:全选案例是后期应用中比较多的案例之一了需要好好掌握,必要的位置敲上备注