jquery provides the Load method to load the data into the page form form, but sometimes I need to get a value in the background JSON data, but also need to assign the entire form form, the Load method does not have a callback function, so it is not, if the use of Ajax calls, After obtaining the JSON data in the background to analyze the JSON data in a single assignment to form the form of each text box, this is too complicated and too much code, so I based on a number of great God's answer, summed up a very useful jquery function.
Jquery-load Method Invocation:
$ (' #form '). Form (' Load ',URL);
Page form:
<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" > Store </option><option value= "2" > HQ </option></select> < TextArea class= "Easyui-validatebox" name= "remark" cols= "+" rows= "5" required= "false" ></textarea></form ></span>
Summary of the method:
Page Call:
<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>
Put this piece of code into jquery and take
<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] ') {//Is a check box and is an 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 ("Checke D "," checked "); } }); }else if ($oinput. attr ("type") = = "textarea") {//Multiline text box Obj.find ("[Name=" +name+ "]"). HTML (ival); }else{Obj.find ("[Name=" +name+ "]"). Val (ival); } });}; </span>
Note that the page launches the Ajax method, then you can get the value you want through AJAX, and you can assign the value to the form form.
After watching the wood has a feeling of love ah.
jquery obtains background JSON data through Ajax to assign values to form forms