zoukankan      html  css  js  c++  java
  • jQuery全选反选

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <script src="./js/jquery-3.6.0.js"></script>
        <script>
            $(function(){
                    //全选
                    $("#chkAll").click(function(){
                        $("input[name=interest]").prop("checked", $(this).prop("checked"));
                    })
                
    
                //反选
                    $("#btnReverse").click(function(){
                        
                        $("input[name=interest]").each(function(){
                            $(this).prop("checked", !$(this).prop("checked"));
                        })
                        
                        checkAll();
                        
                    })
    
                    //检查全选状态
                    $("input[name=interest]").click(function(){
                        checkAll();
                    })
                    function checkAll(){
                        $("#chkAll").prop("checked", $("input[name=interest]:checked").length==$("input[name=interest]").length)
                    }
                
                })
        </script>
    </head>
    <body>
        <input type="checkbox" name="interest"/>唱歌
            <input type="checkbox" name="interest"/>跳舞
            <input type="checkbox" name="interest"/>跑步
            <input type="checkbox" name="interest"/>游泳
            
            <br/>
            
            <input type="checkbox" id="chkAll"/>全选
            <input type="button" value="反选" id="btnReverse"/>
    </body>
    </html>

     

     

     

  • 相关阅读:
    DOM编程
    BOM编程
    JavaScript
    CSS
    HTML入门
    shiro与项目集成开发
    shiro授权测试
    散列算法
    shiro认证流程
    spring boot 入门及示例
  • 原文地址:https://www.cnblogs.com/hr-7/p/14681889.html
Copyright © 2011-2022 走看看