返回js全选反选...登陆

js全选反选

ifhover2019-05-06 10:44:27215

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

<!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:150px;

height:150px;

background-color:red;

}

</style>

</head>

<body>

<input type="checkbox"  id="all"><label for="all">全选</label>

<hr>

<input type="checkbox" name="check[]" id="nth1"><label for="nth1">选项</label>

<input type="checkbox" name="check[]" id="nth2"><label for="nth2">选项</label>

<input type="checkbox" name="check[]" id="nth3"><label for="nth3">选项</label>

<input type="checkbox" name="check[]" id="nth4"><label for="nth4">选项</label>

<input type="checkbox" name="check[]" id="nth5"><label for="nth5">选项</label>

<input type="checkbox" name="check[]" id="nth6"><label for="nth6">选项</label>

<script>

document.getElementById('all').onclick = function(){

var a = document.getElementsByName('check[]');

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

if(document.getElementById('all').checked){

a[i].checked = true;

}else{

a[i].checked = false;

}

}

}

</script>

</body>

</html>

利用循环和if判断来实现功能

最新手记推荐

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

全部回复(0)我要回复

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