返回js实现全选...登陆

js实现全选

xgh2019-03-19 16:23:36215
js 实现全选小功能
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.box{
width: 100px;
height: 260px;
border: 1px solid #ccc;
border-radius: 5px;
padding: 5px 10px;
margin: 20px auto;
}

.box div{
border-bottom: 1px solid #ccc;
padding-bottom: 10px;
}

.box input{
margin: 10px;
}
</style>
</head>

<body>
<div class="box">
<div>
<input type="checkbox" id="checkall" onclick="checkall()"><label for="checkall">全选</label>
</div>
<input type="checkbox" >选项1<br>
<input type="checkbox" >选项2<br>
<input type="checkbox" >选项3<br>
<input type="checkbox" >选项4<br>
<input type="checkbox" >选项5<br>
<input type="checkbox" >选项6<br>
</div>

<script>
function checkall() {
var checkall = document.getElementById('checkall');
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (checkall.checked) {
inputs[i].checked = true;
} else {
inputs[i].checked = false;
}
}
}
</script>
</body>

</html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送