To convert a FORM element to a JSON-formatted object instance code:
In the actual reference, it may be necessary to convert the form element to a JSON format object, that is, the direct amount of the object to facilitate processing, the following is an example code.
The code example is as follows:
<Scripttype= "Text/javascript"> (function($) {$.fn.serializeobject=function(){ varInputs=$( This). Find ("Input,textarea,select"); varo={}; $.each (Inputs,function(i,n) {Switch(N.nodename.touppercase ()) { Case "INPUT": if($ (N). Is (": CheckBox")) { if($ (N). Is (": Checked") ) {O[n.name]=true; } Else{O[n.name]=false; } } Else if($ (N). Is (": Radio")) { if($ (N). Is (": Checked") ) {O[n.name]=N.value; } } Else{O[n.name]=N.value; } Break; Case "TEXTAREA": O[n.name]=$ (n). text (); Break; Case "SELECT": O[n.name]=N.value; Break; } }); returno; }}) (JQuery);</Script>
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=10356
For more information, refer to: http://www.softwhy.com/jquery/
Convert form elements to JSON-formatted object instance code