Jquery中easyui表单元素取值、赋值

####1.Input

  • validatebox

定义:

<input type="text" name="APPLYDEPTNAME" id="APPLYDEPTNAME" style="width: 99%"
                      maxlength="50" class="easyui-validatebox" data-options="required:true" />

赋值:

$("#APPLYDEPTNAME").val('1212');

取值:

$("#APPLYDEPTNAME").val();
  • ComboBox

定义:

<td colspan="5">
            城市:
            <input id="city" style="width: 80px" class="easyui-combobox" data-options=" valueField: 'CityAreaCode', textField: 'CityAreaName', url: '../../Ajax/InforService.ashx?Method=GetCity',  

                 onSelect: function(rec){  
                 var url = '../../Ajax/InforService.ashx?Method=GetArea&CityAreaCode='+rec.CityAreaCode;  

                 $('#area').combobox('reload', url);
                 $('#area').combobox('setValues', '');

                  }" />
            区县:
            <input id="area" class="easyui-combobox" data-options="valueField:'CityAreaCode',textField:'CityAreaName'" />
            街道:
            <input type="text" value="" onchange="doValue(this.value)" style="width: 45%" name="SC001_APPLYDEPTADDRESS"
                maxlength="23" class="easyui-validatebox" id="SC001_APPLYDEPTADDRESS" data-options="required:true" />

赋值:

$("#city2").combobox("getValues")
$("#city").combobox("getValues") + "," + $("#area").combobox("getValues") + "," + $("#SC001_APPLYDEPTADDRESS").val(),

取值:

$('#city').combobox('setValue', ‘北京’);
回显:
                //公司地址
                var str4 = result.APPLYDEPTADDRESS;
                if (str4 != null) {
                    var strs4 = new Array();
                    strs4 = str4.split(",");
                    $('#city').combobox('setValue', strs4[0]);
                    var url = '../../Ajax/InforService.ashx?Method=GetArea&CityAreaCode=' + strs4[0];
                    $('#area').combobox('reload', url);
                    $('#area').combobox('setValue', strs4[1]);
                    $("#APPLYDEPTADDRESS").val(strs4[2]);
                }
  • NumberBox

定义:

<input type="text" class="easyui-numberbox" maxlength="20" name="nn" id="nn" />

赋值:

$('#nn').numberbox('setValue', 206.12);

取值:

var v = $('#nn').numberbox('getValue');
  • DateBox

定义:

<input type="text" name="nn" id="nn" class="easyui-datebox"
   data-options="formatter:myDate.InitDateBox.formatter,parser:myDate.InitDateBox. parser" />

赋值:

$("#SC001_CERTIFICATEVALID").datebox('setValue', '2014-9-12');

取值:

$('#nn').datebox('getValue');
  • NumberSpinner

定义:

<input id="ss" class="easyui-numberspinner" style="width:80px;"  
    required="required" data-options="min:10,max:100,editable:false">  

赋值:

$('#ss').numberspinner('setValue', 8234725);  

取值:

var v = $('#ss').numberspinner('getValue');  
  • menubutton

定义:

<a href="javascript:void(0)" id="mb" name="mb" disabled="true" class="easyui-menubutton"   
data-options="menu:'#mm',iconCls:'icon-edit' ">确认</a>  
<div id="mm" name="mm"style="width:150px;">  
<div data-options="iconCls:'icon-undo'" onclick="initTool.Check('确认通过')">确认通过</div>  
<div data-options="iconCls:'icon-redo'" onclick="initTool.Check('确认不通过')">确认不通过</div>
</div>

####2.Radio

定义

<td height="30" colspan="5">
<input type="radio" name="APPLYDEPTTYPE" value="事业法人" checked="checked" />事业法人
<input type="radio" name="APPLYDEPTTYPE" value="企业法人" />企业法人
<input type="radio" name="APPLYDEPTTYPE" value="社团法人" />社团法人
<input type="radio" name="APPLYDEPTTYPE" value="其他" />其他
</td>

赋值:

var str = result.APPLYDEPTTYPE;
$("[value='" + str + "']").attr("checked", true);

取值:

$('input[name="APPLYDEPTTYPE"]:checked').val();

radio只读:

JQuery 控制 radio 只读

  一、想让radio只读,就是想radio不可以修改。有一种场景是:让没有选中的radio不可以修改。代码如下:

$("input[name='tempProduct.isMustInvoice'][value='0']").attr("disabled",true);

  将值为0的radio设置不可以修改,这种设置的好外是:选中的radio值可以传入后台进行操作。

  二、设置可修改的代码:

$("input[name='tempProduct.isMustInvoice'][value='0']").attr("disabled",false);

  三、将所的radio设置为只读

$("input[name='tempProduct.isMustInvoice']").each(function(){ $(this).attr("disabled",true); });

####3.checkbox

定义:

<td height="60" colspan="5">
&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp
<input type="checkbox" name="BUSINESSSCOPE" value="水" />水 &nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp&nbsp&nbsp
<input type="checkbox" name="BUSINESSSCOPE" value="空气" />空气 &nbsp&nbsp&nbsp&nbsp
&nbsp&nbsp&nbsp&nbsp
<input type="checkbox" name="BUSINESSSCOPE" value="土壤" />土壤</br>
&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp
<input type="checkbox" name="BUSINESSSCOPE" value="噪声" />
噪声 &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp
<input type="checkbox" name="BUSINESSSCOPE" value="生物" />生物
</td>

赋值:

var str3 = result.BUSINESSSCOPE;
        if (str3 != null) {
            var strs = new Array();

            strs = str3.split(",");
            for (i = 0; i < strs.length; i++)
            { $("[value='" + strs[i] + "']").attr("checked", true) };
        }

取值:

var isc = "";
$("input[name='BUSINESSSCOPE']:checked").each(function () { //遍历table里的全部checkbox
isc += $(this).val() + ","; //获取被选中的值
});

if (isc.length > 0) //如果获取到
isc = isc.substring(0, isc.length - 1); //把最后一个逗号去掉string isc就是值

####4.TextArea

定义:

<textarea cols="25" rows="3" name="BUSINESSALLOW" id="BUSINESSALLOW" onpropertychange="if(this.value.length>100){this.value=this.value.substr(0,100)}" class="easyui-validatebox" style="width: 99%; height: 99%" data-options="required:true"></textarea>

赋值和取值与Input标签相同。