• jQuery实现全选、不选和反选功能


    jQuery结合Font Awesome字体图标实现全选、不选和反选功能

    Font Awesome字体图标链接地址:http://www.fontawesome.com.cn/faicons/

    效果:

    代码:

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="font-awesome-4.7.0/css/font-awesome.min.css" />
    
        <style type="text/css">
            label {
                display: inline-flex;
                display: -webkit-inline-flex;
                position: relative;
                cursor: pointer;
                 6%;
            }
            
            .box {
                cursor: pointer;
                 16px;
                height: 16px;
                appearance: none;
                -webkit-appearance: none;
                -moz-appearance: none;
                border: 1px solid lightblue;
                background: lightblue;
            }
            
            .fa-check {
                position: absolute;
                top: 3px;
                left: 2px;
                color: #fff;
                border: none;
            }
            
        </style>
    
    </head>
    
    <body>
        <div class="wrapper">
            <label>
    			<input type="checkbox" class="box"/>
    			<span class="remeber">
    				香蕉
    			</span>
    			<i class="fa fa-fw"></i>
    		</label>
            <label class="wrapper">
    			<input type="checkbox" class="box" />
    			<span class="remeber">
    				苹果
    			</span>
    			<i class="fa fa-fw"></i>
    		</label>
            <label class="wrapper">
    			<input type="checkbox" class="box"/>
    			<span class="remeber">
    				西瓜
    			</span>
    			<i class="fa fa-fw"></i>
    		</label>
            <label class="wrapper">
    			<input type="checkbox" class="box"/>
    			<span class="remeber">
    				橘子
    			</span>
    			<i class="fa fa-fw"></i>
    		</label>
        </div>
    
        <br>
    
        <input type="button" name="" id="check-all" value="全选" />
        <input type="button" name="" id="check-no" value="不选" />
        <input type="button" name="" id="check-reverse" value="反选" />
    
    
        <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function() {
    
                $('body').on("click", ".box", function() {
                    $(this).parent().find('.fa').toggleClass('fa-check');
                });
    
                //全选 
                $("#check-all").click(function() {
                    $(".wrapper label i").each(function() {
                        $(this).addClass("fa-check");
                    })
                });
    
                //不选
                $("#check-no").click(function() {
                    $(".wrapper label i").each(function() {
                        $(this).removeClass("fa-check");
                    })
                });
    
                //反选
                $("#check-reverse").click(function() {
                    $(".wrapper label i").each(function() {
                        $(this).toggleClass("fa-check");
                    })
                });
    
    
            })
        </script>
    </body>
    
    </html>
    

      

  • 相关阅读:
    查看java程序中对象占用空间大小
    elasticsearch的基本了解
    kafka命令及启动
    屠龙之路_大杀技之倚天屠龙_TenthDay
    屠龙之路_坚持就是胜利_NinthDay
    屠龙之路_狭路相逢勇者胜_EighthDay
    屠龙之路_任生活如何虐你,屠龙之路还得继续_SeventhDay
    屠龙之路_假期罢工和公主私奔_SixthDay
    屠龙之路_击败DB小boss_FifthDay
    屠龙之路_转角遇到服务器大魔王_FourthDay
  • 原文地址:https://www.cnblogs.com/qianxuebing/p/9835255.html
Copyright © 2020-2023  润新知