jQuery为Input赋值
一、窗体对话框
1 <div id="WinData" class="easyui-dialog" style="width:265px;height:170px;padding:15px" closed="true" iconCls="icon-app" title="单位资料维护" 2 minimizable="true" maximizable="true" resizable="true" buttons="#WinData-buttons"> 3 <form id="fm" method="post" novalidate> 4 <div class="fitem"> 5 <label>单位编号:</label> 6 <input name="dwbh" style="width:150px"> 7 </div> 8 <div class="fitem"> 9 <label>单位名称:</label> 10 <input name="dwmch" style="width:150px"> 11 </div> 12 <div class="fitem"> 13 <label>备 注:</label> 14 <input name="beizhu" style="width:150px"> 15 </div> 16 </form> 17 </div> 18 <div id="WinData-buttons"> 19 <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="SaveData()">保 存</a> 20 <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#WinData').dialog('close')">取 消</a> 21 </div>
2、设置函数
1 function InitControl() { 2 $.get('../Source/maxbh.ashx', { "action": "maxbh", "tbName": "dwdoc", "fldName": "dwbh" }, function (result) { 3 var result = eval('(' + result + ')'); 4 if (result.success) { 5 var frm = $('#fm'); 6 var name = "dwbh"; 7 SetInputValue(frm, name, result.maxbh); 8 var names = "dwmch,beizhu"; 9 SetInputEmpty(frm, names); 10 } else { 11 AlterError("系统初始化失败!"); 12 } 13 }); 14 }
1 function SetInputEmpty(frm, Names) { 2 var Arr = Names.split(","); 3 for (var i = 0; i < Arr.length; i++) { 4 var name = Arr[i]; 5 var txt = frm.find("input[name=\"" + name + "\"]"); 6 txt.val(""); 7 } 8 } 9 10 function SetInputValue(frm, Name, Value) { 11 var txt = frm.find("input[name=\"" + Name + "\"]"); 12 txt.val(Value); 13 //txt[0].value = vallue; 14 }