Convert form elements to json format object instance code, form json
Convert form elements to json format object instance code:
In actual reference, it is possible to convert form elements into json-format objects, that is, the amount of objects directly for processing. Below is an example code like this.
The code example is as follows:
<script type="text/javascript"> (function($){ $.fn.serializeObject=function(){ var inputs=$(this).find("input,textarea,select"); var o={}; $.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; } }); return o; } })(jQuery);</script>
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 10356.
For more information, see: http://www.softwhy.com/jquery/