zoukankan      html  css  js  c++  java
  • 超简单全选/反选/不选

    JQ

    <script src="jquery-1.8.3.min.js"></script>
        <script type="text/javascript">
            function Select(obj) {
                //获取参数
                var str = $(obj).attr('data-name');
                //获取name=color的input标签
                var name = $('input[name=color]');
                //循环name=color的input标签
                for (var i = 0; i < name.length; i++) {
                    switch (str) {
                        case 'Q':
                            //全选为true
                            name[i].checked = true;
                            break;
                        case 'F':
                            //取反为对立
                            name[i].checked = !name[i].checked;
                            break;
                        case 'B':
                            //不选为false
                            name[i].checked = false;
                            break;
                    }
                }
            }

    //var num = $("input[type=checkbox]:checked").length;
        </script>

    HTML

    <input type="checkbox" name="color" value="红色" />红色
        <input type="checkbox" name="color" value="黑色" />黑色
        <input type="checkbox" name="color" value="绿色" />绿色
        <input type="checkbox" name="color" value="蓝色" />蓝色
        <br />
        <br />
        &nbsp<input type="button" name="name" value="全选" data-name="Q" onclick="Select($(this))" />
        &nbsp<input type="button" name="name" value="反选" data-name="F" onclick="Select($(this))" />
        &nbsp<input type="button" name="name" value="不选" data-name="B" onclick="Select($(this))" />

  • 相关阅读:
    EOJ 2743 Stock Exchange
    POJ-3468 A Simple Problem with Integers
    EOJ-1104 bitmap
    【转】旋转卡壳——凸多边形间对踵点对(定义)
    Ring 3层枚举进程的四种方法
    XX-Net项目,免费浏览谷歌的伟大项目
    浅析Java中的内存机制
    Ubuntu下eclipse中安装Scala插件
    注入(5)---导入表注入(HookINT)
    Linux下MySQL导入文件出错ERROR 1290 (HY000)
  • 原文地址:https://www.cnblogs.com/LD1018/p/7942692.html
Copyright © 2011-2022 走看看