欢迎各位兄弟 发布技术文章
这里的技术是共享的
jQuery-load方法调用:
$(‘#form‘).form(‘load‘,URL);
页面表单:
<span style="font-size:18px;"><form id="form" action="system/info/area_operate.html" method="post" class="default">
<input type="text" name="area_name" readOnly/>
<input type="text" name="name"/>
<select id="type" name="type" >
<option value="1">门店</option>
<option value="2">总部</option>
</select>
<textarea class="easyui-validatebox" name="remark" cols="40" rows="5" required="false"></textarea>
</form></span>
总结的方法:
页面调用:
<span style="font-size:18px;"><script> <span style="white-space:pre"> </span>$.getJSON(URL,param,function(data){ <span style="white-space:pre"> </span>alert(data.type); <span style="white-space:pre"> </span>$("form").setForm(data); }); </script></span>
<span style="font-size:18px;">$.fn.setForm = function(jsonValue) { alert("setForm"); var obj=this; $.each(jsonValue, function (name, ival) { var $oinput = obj.find("input:[name=" + name + "]"); if ($oinput.attr("type")== "radio" || $oinput.attr("type")== "checkbox"){ $oinput.each(function(){ if(Object.prototype.toString.apply(ival) == '[object Array]'){//是复选框,并且是数组 for(var i=0;i<ival.length;i++){ if($(this).val()==ival[i]) $(this).attr("checked", "checked"); } }else{ if($(this).val()==ival) $(this).attr("checked", "checked"); } }); }else if($oinput.attr("type")== "textarea"){//多行文本框 obj.find("[name="+name+"]").html(ival); }else{ obj.find("[name="+name+"]").val(ival); } }); };</span>
看了之后有木有感觉很有爱啊。
来自 http://www.bubuko.com/infodetail-502093.html