zoukankan      html  css  js  c++  java
  • jquery cheched 全选/全不选

    <!DOCTYPE html>
    <html>

        <head>
            <title>Jquery复选框练习</title>
            <!-- 引入jQuery,引入你自己的jQuery文件 -->
            <script type="text/javascript" src="../scripts/jquery-1.7.2.js"></script>
        </head>

        <body>
            <div>
                <p>选择要购买的水果</p>
                <ul class="fruit">
                    <li><input type="checkbox" value="001" />苹果</li>
                    <li><input type="checkbox" value="002" />雪梨</li>
                    <li><input type="checkbox" value="003" />芒果</li>
                    <li><input type="checkbox" value="004" />菠萝</li>
                </ul> <input type="checkbox" id="All" /> <button id="checkAll">全选</button> <button id="nothing">
                    全不选</button> <button id="reverseAll">反选</button> <button class="chooseFruit">购买</button>
                <script type="text/javascript">
                    <!-- 选择全部/全不选 -->
                    $("#All").click(function(){ if("this.checked"){
                        $("#fruit :checkbox").prop("checked", true);
                    }else{
                        $("#fruit :checkbox").prop("checked", false);
                    }
                    });
                    <!--选择全部-->
                    $("#checkAll").click(function(){ $("#fruit :checkbox").prop("checked", true); });
                    <!--全不选-->
                    $("#nothing").click(function(){ $("#fruit :checkbox").prop("checked", false); });
                    <!--反选--> $("#reverseAll").click(function(){ $("#fruit :checkbox").each(function(i){
                        $(this).prop("checked",
                        !$(this).prop("checked"));
                    });
                    });
                    <!--获取选中复选框的值--> $(".chooseFruit").click(function(){
                        var arr = new Array();
                        $("#fruit :checkbox[checked]").each(function(i){
                            arr[i] = $(this).val();
                        });
                        var vals = arr.join(",");
                        console.log(vals); });
                </script>
            </div>
        </body>

    </html>

  • 相关阅读:
    在 macOS High Sierra 10.13 搭建 PHP 开发环境
    给你的网站免费配置上 HTTPS 证书
    将 MacOS 默认的 PHP 版本升级到 7.*
    System.Data.SqlClient.SqlException: 'Incorrect syntax near 'OFFSET'.
    IIS7/8 HTTP Error 500.19 错误 0x80070021 错误代码:0x8007000d
    http error 502.5
    信用卡逾期了怎么办 ?逾期记录“修复”的两大原则
    APP多开教程
    lua调用不同lua文件中的函数
    Lua 用指定字符或字符串分割输入字符串,返回包含分割结果的数组
  • 原文地址:https://www.cnblogs.com/gerry/p/8688601.html
Copyright © 2011-2022 走看看