zoukankan      html  css  js  c++  java
  • 使用JQuery获取被选中的checkbox的value值

    <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>
    var disabled_group=[];
    $.each($('input[name=disabled_group]:checked'),function(){
       disabled_group.push($(this).val());
    });
    
    field.disabled_group=disabled_group.join();
    if(_this.form.disabled_group != null){
        disabledGroup = _this.form.disabled_group.split(',')
    }
    
    for (var idx = 0; idx < _this.group_list.length; idx++) {
      for(var i = 0; i < disabledGroup.length; i++){
        if(disabledGroup[i] == _this.group_list[idx]['group_id']){
          $('input[name=disabled_group]').eq(idx).prop("checked", true);
        }
      }
    }
    
  • 相关阅读:
    iPhone将NSString转换编码集为gb2312或者gbk的方法
    iOS下微信语音播放之切换听筒和扬声器的方法解决方案
    苹果开发者各地区联系电话
    iOS开发中,应用内直接跳转到Appstore
    高亮显示UILabel中的子串
    UML
    All Classic Bluetooth profile for iPhone
    智能穿戴设备移动APP端与外设数据传输协议功能模块CMD&ACK表
    Mac 使用技巧分享
    git branch管理小结
  • 原文地址:https://www.cnblogs.com/vania/p/10614912.html
Copyright © 2011-2022 走看看