To sequence a form element as an object code instance:
Sometimes it may be more convenient to serialize a form element and then manipulate it, and here's a piece of code that can do this.
The code is as follows:
functionSerializeObject (form) {varo={}; $.each (Form.serializearray (),function(index) {if(o[ This[' Name ']]) {o[ This[' name ']] =o[ This[' name ']] +","+ This[' Value ']; } Else{o[ This[' name ']] = This[' Value ']; } }); returno;}
The above code implements our requirements to serialize the form elements into an object, following a simple comment on the code.
A. Code Comment:
1.function SerializeObject (form) {}, the parameter is a form form object, and of course it must be a jquery object.
2.var o={}, declares that an empty object is used to store the name and value values of the form element, the object's property name is the table cell Name property value, and the property value is the value of the form element.
3.$.each (Form.serializearray (), function (index) {}), Form.serializearray () returns an array, the element is the direct amount of the object, and each object has a direct amount of two two name-value pairs, One is the Name/name property value and the other is the Value/value property value. $.each () can traverse the created array.
4.if (o[this[' name ']) {o[this[' name ']]=o[this[' name ']]+ ', ' +this[' value '], and if the object already has a property name for the response, then concatenate the string and reset the property value again. This applies to similar cases where multiple check boxes with the same name are selected.
5.else{o[this[' name ']]=this[' value ';}, create the property and assign a value.
6.return o, returns the generated object.
Two. Related reading:
The 1.serializeArray () function can be found in the Serializearray () method section of jquery .
2. Direct volume of the object can refer to the direct volume of JS object A brief introduction of the chapter.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=13566
For more information, refer to: http://www.softwhy.com/jquery/
Sequence a form element as an object code instance