• 获取复选框的值


     JS获取复选框的值

    function getCheckAdIds() {  
        var adIds = "";  
        $("input:checkbox[name=check_name]:checked'").each(function(i){  
            if(0==i){  
                adIds = $(this).val();  
            }else{  
                adIds += (","+$(this).val());  
            }  
        });  
        alert(adIds);  
        return adIds;  
    }  

    JS实现全选

    http://blog.csdn.net/sunwei3160/article/details/38515187

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>js点击checkbox实现全选效果</title>
    <script type="text/javascript">
        function DoCheck() {
            var ch = document.getElementsByName("choose");
            if (document.getElementsByName("allChecked")[0].checked == true) {
                for (var i = 0; i < ch.length; i++) {
                    ch[i].checked = true;
                }
            } else {
                for (var i = 0; i < ch.length; i++) {
                    ch[i].checked = false;
                }
            }
        }
    </script>
    </head>
    
    <body>
        请选择爱好:
        <br />
        <input type="checkbox" name="choose">跳舞
        <input type="checkbox" name="choose">跳水
        <input type="checkbox" name="choose" />跳棋
        <input type="checkbox" name="choose" />跑步
        <br />
        <input type="checkbox" name="allChecked" id="allChecked"
            onclick="DoCheck()" />全选/取消
    </body>
    </html>
    

      

    //一个或者多个没选,则全选按钮不被选中,全选之后则全选按钮自动选中
         function SelectOne(dh2){
             var selCount = 0;
             var unSelCount = 0;
             var ch = document.getElementsByName(dh2);
             var all=document.getElementsByName(dh2)[0];
             for(var i=1;i<ch.length;i++){
                 if(ch[i].checked==true){
                  selCount++;
                 }
                 if(ch[i].checked==false){
                  unSelCount++;
                 }
                 if(selCount==ch.length-1){
                  all.checked=true;
                 }
                 if(unSelCount>0){
                  all.checked=false;
                 }
            }
         }
    

      

  • 相关阅读:
    bzoj1904: Musical Water-fence
    bzoj3822: 文学
    bzoj1513: [POI2006]Tet-Tetris 3D
    bzoj4130: [PA2011]Kangaroos
    bzoj2515 Room
    bzoj2518: [Shoi2010]滚动的正四面体
    bzoj4617: [Wf2016]Spin Doctor
    bzoj3086: Coci2009 dvapravca
    bzoj3745: [Coci2015]Norma
    bzoj1837: [CROATIAN2009]cavli 凸包1
  • 原文地址:https://www.cnblogs.com/miye/p/8533764.html
Copyright © 2020-2023  润新知