zoukankan      html  css  js  c++  java
  • checkbox的全选,取消全选,获得选中值

    <html>
    <head>
    <title>jq全选以及获得选中项的值</title>
    <meta charset="utf-8">
    
    <script src="http://libs.baidu.com/jquery/1.4.1/jquery.js"></script>
    <script>
    $(function() {
        $("#select").click(function() {
            if ($(this).attr("checked")) {
                $("input[name=items]").each(function() {
                    $(this).attr("checked", true);
                });
            } else {
                $("input[name=items]").each(function() {
                    $(this).attr("checked", false);
                });
            }
        });
        //得到选中的值,ajax操作使用
        $("#submit").click(function() {
            var text="";
            $("input[name=items]").each(function() {
                if ($(this).attr("checked")) {
                    text += ","+$(this).val();
                }
            });
             alert(text);
        });
    });
    </script>
    </head>
    <body>
    <form action="#" method="post">
        <input type="checkbox" value="1" name="items"><br/>
        <input type="checkbox" value="2" name="items"><br/>
        <input type="checkbox" value="3" name="items"> <br/>
        <input type="checkbox" value="4" name="items"> <br/>
        <input type="checkbox" value="5" name="items"> <br/>
        <input type="checkbox" value="6" name="items"> <br/>
        <input type="checkbox" value="7" name="items"> <br/>
        <input type="checkbox" value="8" name="items"> <br/>
        <input type="checkbox" value="9" name="items"> <br/>
        <input type="checkbox" value="10" name="items"> <br/>
        <input type="checkbox" value="11" name="items"> <br/>
    	<input type="checkbox" id="select"/> 全选<br/>
        <input type="submit" id="submit" value="提交">
    </form>
    </body>
    </html>
    

      好像高版本的jq库会有问题,待研究。。。。。

  • 相关阅读:
    DI 之 3.4 Bean的作用域(捌)
    DI 之 3.3 更多DI的知识(柒)
    MySQL中基本的多表连接查询教程
    DI 之 3.3 更多DI的知识(陆)
    字符串(string)转json
    如何查看连接mysql的ip地址
    DI 之 3.2 循环依赖 (伍)
    DI 之 3.1 DI的配置使用(肆)
    IoC 之 2.3 IoC的配置使用(叁)
    MySQL for Windows 解压缩版配置安装
  • 原文地址:https://www.cnblogs.com/phpjinggege/p/5647736.html
Copyright © 2011-2022 走看看