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))" />

  • 相关阅读:
    JVM内存模型
    052-224(新增70题2018)
    052-223(新增70题2018)
    052-222(新增70题2018)
    052-221(新增70题2018)
    052-220(新增70题2018)
    052-219(新增70题2018)
    052-218(新增70题2018)
    052-217(新增70题2018)
    052-216(新增70题2018)
  • 原文地址:https://www.cnblogs.com/LD1018/p/7942692.html
Copyright © 2011-2022 走看看