zoukankan      html  css  js  c++  java
  • JQuery获取input checkbox

    // 全选
       
        $('#allcheck').click(function(){
    
            $('input[name="check"]').prop('checked','true');
        });
    
        //反选
        $('#reversecheck').click(function(){
            $('input[name="check"]').each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
    
        });
    被选中的值代码:
    
    <html>
        <head>
            <meta charset="gbk">
            <!-- 引入JQuery -->
            <script src="jquery-1.3.1.js" type="text/javascript"></script>
        </head>
    
        <body>
            <input type="checkbox" value="橘子" name="check">橘子1</input>
            <input type="checkbox" value="香蕉" name="check">香蕉1</input>
            <input type="checkbox" value="西瓜" name="check">西瓜1</input>
            <input type="checkbox" value="芒果" name="check">芒果1</input>
            <input type="checkbox" value="葡萄" name="check">葡萄1</input>
            
            <input type="button" value="方法1" id="b1">
            <input type="button" value="方法2" id="b2">
    
    
        </body>
        
        <script>
            //方法1
            $("#b1").click(function(){
                //$('input:checkbox:checked') 等同于 $('input[type=checkbox]:checked')
                //意思是选择被选中的checkbox
                $.each($('input:checkbox:checked'),function(){
                    window.alert("你选了:"+
                        $('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
                });
            });
            
            //方法2
            $("#b2").click(function(){
                $.each($('input:checkbox'),function(){
                    if(this.checked){
                        window.alert("你选了:"+
                            $('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
                    }
                });
            });
        </script>
    </html>
    

      

  • 相关阅读:
    进程与线程
    linux网关服务器
    linux硬盘分区和fdisk命令
    MyISAM与InnoDB两者之间区别与选择(转)
    系统吞吐量与QPS/TPS
    linux最大打开文件句柄数
    内存性能测试 Memtester+mbw
    硬盘性能测试
    使用JNA访问WindowsAPI操作Windows窗口元素
    [博客页面装饰]----[人体时钟]插件
  • 原文地址:https://www.cnblogs.com/liuzhiw/p/7823486.html
Copyright © 2011-2022 走看看