-
Notifications
You must be signed in to change notification settings - Fork 0
/
js全选功能.html
65 lines (58 loc) · 1.46 KB
/
js全选功能.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
全选功能自写
<table>
<thead>
<tr>
<th >
<input type="checkbox" name="all" id="ischange" >
</th>
<th>序号</th>
<th>小说ID</th>
<th>小说名称</th>
</tr>
</thead>
<tbody>
<tr class="">
<td> <input type="checkbox" name="ids" onchange="checkAll()" value=""></td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr class="">
<td> <input type="checkbox" name="ids" onchange="checkAll()" value=""></td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
<script>
//获得选中值
function getIds() {
var chk_value =[];
$('input[name="ids"]:checked').each(function(){
chk_value.push($(this).val());
});
return chk_value;
}
$("#ischange").change(function() {
if($("input[name='all']").is(':checked')) {
$("input[name='ids']").prop('checked',true);
}else{
$("input[name='ids']").prop('checked',false);
}
});
function checkAll()
{
var check = 0;
$('input[name="ids"]').each(function(){
if(!($(this).is(':checked'))) {
check = 1;
}
});
if(check){
$("input[name='all']").prop('checked',false);
}else{
$("input[name='all']").prop('checked',true);
}
}
</script>