返回全选框_whi......登陆

全选框_while实现

             2019-01-13 19:34:18290

<!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>

div{margin:0px auto;}

.box{width:230px;height: 220px;border: 1px solid black;border-radius:5px;padding:5px 10px;}

.box_all{border-bottom: 1px solid black;padding-bottom: 10px;}

.box_option{padding: 10px 0px;}

.box_option input{margin:10px;}

</style>

<script>

var checkall,checkall_while,item;

window.onload = function(){

checkall = document.getElementById("checkall");

checkall_while = document.getElementById("checkall_while");

item = document.getElementsByName("item[]");

}

function checkAll(){

checkall_while.checked = false;

for (let i = 0; i < item.length; i++) {

if (checkall.checked) {

item[i].checked = true;

} else {

item[i].checked = false;

}

}

}

function checkAll_while(){

checkall.checked = false;

var i = 0;

while (i<item.length ) {

if (checkall_while.checked) {

item[i].checked = true;

} else {

item[i].checked = false;

}

i++;

}

}

</script>

</head>

<body>

<div class="box">

<div class="box_all">

<input type="checkbox" id="checkall" onclick="checkAll()">

<label for="chackall">全选(for)</label>

&nbsp;

<input type="checkbox" id="checkall_while" onclick="checkAll_while()">

<label for="chackall">全选(while)</label>

</div>

<div class="box_option">

<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>

</div>

</div>

</body>

</html>


最新手记推荐

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

全部回复(0)我要回复

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