• ☀【表单】checkbox


    全选 / 全不选 / 反选

     http://www.css88.com/

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <div id="checked">    
            <input name="checkbox" value="checkbox1" id="checkbox1" type="checkbox">
            <input name="checkbox" value="checkbox2" id="checkbox2" type="checkbox">
            <input name="checkbox" value="checkbox3" id="checkbox3" type="checkbox">     
            <input name="checkbox" value="checkbox4" id="checkbox4" type="checkbox">  
            <input name="checkbox" value="checkbox5" id="checkbox5" type="checkbox">
        </div>
        <input name="button1" id="button1" value="全选" type="submit">
        <input name="button2" id="button2" value="全不选" type="submit">
        <input name="button3" id="button3" value="反选" type="submit">
        <input name="button4" id="button4" value="看看我选择了什么" type="submit">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script>
            (function ($) {
                $.fn.checkBox = function (state) {
                    this.each(function () {
                        switch (state) {
                            case 'all':
                                $(this).attr("checked", true);
                                break;
                            case 'none':
                                $(this).attr("checked", false);
                                break;
                            case 'toggle':
                                $(this).attr("checked", !this.checked);
                                break;
                        }
                    });
                };
                $.fn.checkedValue = function () {        
                    var str = '';
                    this.each(function () {
                        str += $(this).val() + ",";            
                    })
                    return str;
                };
            })(jQuery);
    
            $(function () {
                $("#button1").bind("click", function () {
                    $("#checked input[type=checkbox]").checkBox("all");
                });
                $("#button2").bind("click", function () {
                    $("#checked input[type=checkbox]").checkBox("none");
                });
                $("#button3").bind("click", function () {
                    $("#checked input[type=checkbox]").checkBox("toggle");
                });
                $("#button4").bind("click", function () {
                    alert($("#checked input[type=checkbox][checked]").checkedValue());
                });
            });
        </script>
    </body>
    </html>
  • 相关阅读:
    小程序开发 access_token 统一管理
    python操作mysql
    Mac版本的idea非正常关闭后,idea打开项目大面积报红
    PySpider爬取去哪儿攻略数据项目
    Python3.9安装PySpider步骤及问题解决
    Selenium 自动化测试工具
    Python 抓取猫眼电影排行
    Python爬虫基本库
    Python 创建一个Django项目
    Python 数据可视化
  • 原文地址:https://www.cnblogs.com/jzm17173/p/2936932.html
Copyright © 2020-2023  润新知