-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-064.html
70 lines (57 loc) · 1.81 KB
/
ex-064.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<meta charset="utf-8">
<title>練習:一次全選 / 全部取消 checkbox 勾選格</title>
<style type="text/css">
body{
padding: 1em; font-size: 20px;
}
.wraps{
margin-top: 1em;
}
label{
display: inline-block; margin-left: 1em; font-weight: 500;
}
</style>
</head>
<body>
<button class="btn-allChecked">全選 / 取消</button>
<div class="wraps">
<label><input type="checkbox" name="chkbox" id="">AA</label>
<label><input type="checkbox" name="chkbox" id="">BB</label>
<label><input type="checkbox" name="chkbox" id="">CC</label>
<label><input type="checkbox" name="chkbox" id="">DD</label>
<label><input type="checkbox" name="chkbox" id="">EE</label>
<label><input type="checkbox" name="chkbox" id="">FF</label>
<label><input type="checkbox" name="chkbox" id="">GG</label>
<label><input type="checkbox" name="chkbox" id="">HH</label>
<label><input type="checkbox" name="chkbox" id="">II</label>
<label><input type="checkbox" name="chkbox" id="">JJ</label>
</div>
<script src="scripts/jquery-3.1.0.js"></script>
<script type="text/javascript">
// todo: 把前一個練習中的全選/取消合併成一個按鈕
$('.btn-allChecked').on('click', function(){
//var isActive = false;
//$('input[name="chkbox"]').each(function(i,v){
// console.log($(v).prop('checked'));
// if ($(v).prop('checked'))
//{
// isActive = true;
//}
//$('input[name="chkbox"]').prop('checked', !isActive);
//}
if($('input[name="chkbox"]').prop('checked'))
{
$('input[name="chkbox"]').prop('checked', false);
}
else
{
$('input[name="chkbox"]').prop('checked', true);
}
});
</script>
</body>
</html>