zoukankan      html  css  js  c++  java
  • jqGrid radio,checkbox操作 radio checkbox in jqgrid

    Jquery老的版本
    var_name = $(“input[@name='radio_name']:checked”).val();
    Jquery 1.3以后的版本
    var_name = $(“input[name='radio_name']:checked”).val();//选择被选中Radio的Value值


     $("input[name='radio_name'][checked]").val(); //选择被选中Radio的Value值  

     $("#text_id").focus(function(){//code...}); //事件 当对象text_id获取焦点时触发  

     $("#text_id").blur(function(){//code...}); //事件 当对象text_id失去焦点时触发  

     $("#text_id").select(); //使文本框的Vlaue值成选中状态  

     $("input[name='radio_name'][value='要选中Radio的Value值 '").attr("checked",true); //根据Value值设置Radio为选中状态   
     
    CheckBox   
      
     $("input[name='checkbox_name'][checked]");or$("input[name='checkbox_name']:checked");/选择被选中CheckBox元素的集合 如果你想得到Value值,你需要遍历这个集合 

     $($("input[name='checkbox_name'][checked]")).each(function(){arrChk+=this.value + ',';}); //遍历被选中CheckBox元素的集合 得到Value值  

     $("#checkbox_id").attr("checked"); //获取一个CheckBox的状态(有没有被选中,返回true/false)  

     $("#checkbox_id").attr("checked",true); //设置一个CheckBox的状态为选中(checked=true)  

     $("#checkbox_id").attr("checked",false); //设置一个CheckBox的状态为不选中(checked=false)  

     $("input[name='checkbox_name']").attr("checked",$("#checkbox_id").attr("checked")); //根据3,4,5条,你可以分析分析这句代码的意思  

     $("#text_id").val().split(","); //将Text的Value值以','分隔 返回一个数组

     

    formatter:function(v,x,r){ return "<input type='checkbox'/>"; }

    jqGrid中multiselect: true的用法 (2011-12-12 10:58:35)
    转载▼标签: jqgrid it 分类: JQuery
    在jqGrid中设置multiselect: true可以实现全选的操作,但怎么设置被选中的checkbox里面的值呢,做法如下:
    jQuery("#listTable").jqGrid({
       url: 'queryList.do',
       datatype: 'json',
       colNames: ['','编号','姓名'],
       colModel: [
                   {
                     name: 'MY_ID',
                     index: 'MY_ID',
                     sortable: false,
                     '0%',
                     hidden:true
                   },
                   {
                     name: 'MY_NO',
                     index:'MY_NO',
                     sortable: false,
                     align:'center',
                     '10%'
                   },
                  {
                     name: 'NAME',
                     index:'NAME',
                     sortable: false,
                     align:'center',
                     '10%'
                  }
                ],
                page: 1,
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#listPage',
                multiselect: true,
                sortname: 'MY_NO',
                viewrecords: true,
                sortorder: "desc",
                jsonReader: {
                    repeatitems: false
                },
                "100%",
                height: '100%',
                gridComplete: function() {
                    var rowIds = jQuery("#listTable").jqGrid('getDataIDs');
                    for(var k=0; k<rowIds.length; k++) {
                       var curRowData = jQuery("#listTable").jqGrid('getRowData', rowIds[k]);
                       var curChk = $("#"+rowIds[k]+"").find(":checkbox");
                       curChk.attr('name', 'checkboxname');   //给每一个checkbox赋名字
                       curChk.attr('value', curRowData['MY_ID']);   //给checkbox赋值
                       curChk.attr('title', curRowData['NAME'] );   //给checkbox赋予额外的属性值
                       //curChk.attr('checked', 'true');   //设置所有checkbox被选中
                    }


                    //下面的代码顺序不能变(这是页面上所有行被真选中[所有行被黄色])
                    //$("#cb_listTable").attr("checked", true);
                    //$("#cb_listTable").click();   //input框
                    //$("#jqgh_listTable_cb").click();   //div标签
                    //$("#listTable_cb").click();   //th标签
                }
    });

    加载完列表后获取被选中的checkbox的值及其属性值的做法如下:
    var checkedVals = new Array();
    var checkedTitles = new Array();
    $(":checkbox[name=checkboxname][checked]").each(function(){
          checkedVals.push($(this).val());
          checkedTitles.push($(this).attr("title"));
    });
    for(var p=0; p<checkedVals.length; p++){
        alert(checkedVals[p]);
        alert(checkedTitles[p]);
    }

    --------------------------------------------------------------------------------------------------
    让查询列表中按指定条件被默认选中或灰掉checkbox的做法如下:
    jQuery("#listTable").jqGrid({
       url: 'queryList.do',
       datatype: 'json',
       colNames: ['','编号','姓名'],
       colModel: [
                   {
                     name: 'MY_ID',
                     index: 'MY_ID',
                     sortable: false,
                     '0%',
                     hidden:true
                   },
                   {
                     name: 'MY_NO',
                     index:'MY_NO',
                     sortable: false,
                     align:'center',
                     '10%'
                   },
                  {
                     name: 'NAME',
                     index:'NAME',
                     sortable: false,
                     align:'center',
                     '10%'
                  }
                ],
                page: 1,
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#listPage',
                multiselect: true,
                multiboxonly: true,
                sortname: 'MY_NO',
                viewrecords: true,
                sortorder: "desc",
                jsonReader: {
                    repeatitems: false
                },
                "100%",
                height: '100%',
                gridComplete: function() {
                    var rowIds = jQuery("#listTable").jqGrid('getDataIDs');
                    for(var k=0; k<rowIds.length; k++) {
                       var curRowData = jQuery("#listTable").jqGrid('getRowData', rowIds[k]);
                       if(curRowData.MY_NO == '123456'){
                            $("#listTable").find("input[id='jqg_" + rowIds[k] +
                                                                          "']").val(curRowData.MY_ID);
                            if(curRowData.NAME=='shihuan'){
                                $("#listTable").find("input[id='jqg_" + rowIds[k] +
                                                                          "']").attr("checked", true);
                            }
                        }else{
                            $("#listTable").find("input[id='jqg_" + rowIds[k] +
                                                                          "']").val(curRowData.MY_ID);
                            $("#listTable").find("input[id='jqg_" + rowIds[k] + "']").attr("checked",
                                                                                                true);
                            $("#listTable").find("input[id='jqg_" + rowIds[k] + "']").attr("disabled",
                                                                                                true);
                        }
                    }
                }
                onSelectAll:function(rowid, status) { //rowid 数组
                    var ids = jQuery("#listTable").jqGrid('getDataIDs');
                    for (var i=0; i<ids.length; i++) {
                        var cl = ids[i];
                        var curRowData = jQuery("#listTable").jqGrid('getRowData', cl);
                        var ckt = $("#listTable").find("input[id='jqg_" + cl + "']").attr("disabled");
                        if(ckt){
                            $("#listTable").find("input[id='jqg_" + cl + "']").attr("checked", true);
                        }
                    }
                },
                beforeSelectRow:function(rowid, e){
                    //alert(rowid);   //rowid的值是checkbox的value值
                    return false;
                }
    });
    --------------------------------------------------------------------------------------------------
    jqGrid被重新载入的做法如下:
    function gridReload() {
        jQuery("#listTable").jqGrid('setGridParam', {
                    //url:'http://www.cnblogs.com/../com/shihuan/search.do',
                    //postData: transferFormElementsToObject('theForm'),
                    postData: {"message":msval},
                    page:1
                }).trigger("reloadGrid");
    }

     

    每一天都要行动,在前进中寻求卓越。
  • 相关阅读:
    NSInvocation的基本使用
    OC和JS代码的互调
    HTTPS的基本使用
    数据安全
    AFN框架
    部分文件的MIMEType
    linux中文件颜色,蓝色,白色等各自代表的含义
    CentOS下mysql常用命令
    mysql 完整备份和恢复
    mysqldump 导出提示Couldn't execute SELECT COLUMN_NAME...
  • 原文地址:https://www.cnblogs.com/wshsdlau/p/2868861.html
Copyright © 2011-2022 走看看