$.fn.extend ({
Call Mode: $ ("xxxxx"). GetForm ();
Getform:function () {var obj = {}; var array = $ (this). Serializearray (); $.each (array, function () {obj[this.name] = This.value; }); return obj; },//Call Way: $ ("xxx"). Setform (JSON); Setform:function (jsonvalue) {var obj = this; $.each (Jsonvalue, function (name, ival) {var $input = Obj.find ("input:[name=" + name + "]"); if ($input. attr ("type") = = "Radio" | | $input. attr ("type") = = "checkbox") {$input. 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", "ch Ecked "); }} else {if ($ (this). val () = = ival) $ (this). attr ("Checked", "checked"); } }); } else if ($input. attr ("type") = = "textarea") {//Multiline text box Obj.find ("[name=" + name + "]"). HTML (ival); } else {obj.find ("[name=" + name + "]"). Val (ival); } }); }
});
JS get form form data and form form assignment value