码迷,mamicode.com
首页 > Web开发 > 详细

jQuery--全选、反选、取消

时间:2016-02-21 18:29:21      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

主要知识点:

prop()--主要检查和设置checked

代码:
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <input type="button" value="全选" onclick="CheckAll()"/>
    <input type="button" value="反选" onclick="CheckReverse()"/>
    <input type="button" value="取消" onclick="CheckCancel()"/>
 
    <table border="1">
        <thead></thead>
        <tbody id="tb1">
            <tr>
                <td><input type="checkbox" /></td>
                <td>11</td>
            </tr>
            <tr>
                <td><input type="checkbox" /></td>
                <td>22</td>
            </tr>
            <tr>
                <td><input type="checkbox" /></td>
                <td>33</td>
            </tr>
        </tbody>
    </table>
    <script type="text/javascript" src="jquery-2.1.4.min.js"></script>
    <script type="text/javascript">
        function CheckAll(){
            $(‘#tb1‘).find(‘:checkbox‘).prop(‘checked‘,true);
        }
        function CheckReverse(){
            $(‘#tb1‘).find(‘:checkbox‘).each(function(){
                //$(this)=每一个复选框
                //$(this).prop(‘checked‘)如果选中,true,否则false
                if ($(this).prop(‘checked‘)){
                    $(this).prop(‘checked‘,false);
                }else{
                    $(this).prop(‘checked‘,true);
                }
            });
        }
        function CheckCancel(){
            $(‘#tb1‘).find(‘:checkbox‘).prop(‘checked‘,false);
        }
    </script>
</body>
</html>
效果:?

技术分享?















jQuery--全选、反选、取消

标签:

原文地址:http://www.cnblogs.com/daliangtou/p/5205282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!