instance
Output serialization Form value results:
Copy Code code as follows:
$ ("button"). Click (function () {
$ ("div"). Text ($ ("form"). Serialize ());
});
Definitions and Usage
The serialize () method creates a URL-encoded text string by serializing the form value.
You can select one or more form elements (such as input and/or text boxes), or the form element itself.
The serialized value can be used in the URL query string when generating an AJAX request.
Grammar
Copy Code code as follows:
$ (selector). Serialize ()
Detailed description
The. Serialize () method creates a text string that is represented by a standard URL encoding. Its action object is a JQuery object that represents a collection of form elements.
There are several types of form elements:
Copy Code code as follows:
<form>
<div><inputtype= "text" Name= "a" value= "1" id= "a"/></div>
<div><inputtype= "text" name= "B" value= "2" id= "B"/></div>
<div><inputtype= "hidden" name= "C" value= "3" id= "C"/></div>
<div>
<textareaname= "D" rows= "8" cols= ">4</textarea>"
</div>
<div><selectname= "E" >
<optionvalue= "5" selected= "selected" >5</option>
<optionvalue= "6" >6</option>
<optionvalue= "7" >7</option>
</select></div>
<div>
<inputtype= "checkbox" Name= "F" value= "8" id= "F"/>
</div>
<div>
<inputtype= "Submit" name= "G" value= "Submit" id= "G"/>
</div>
</form>
The. Serialize () method can manipulate JQuery objects that have selected individual form elements, such as <input>, <textarea>, and <select>. However, it is generally easier to choose <form> label itself to serialize:
$ (' form '). Submit (function () {
Alert ($ (this). Serialize ());
Returnfalse;
});
output standard query string:
A=1&b=2&c=3&d=4&e=5
Note: Only successful controls will be serialized as strings. If you do not use a button to submit the form, the value of the Submit button is not serialized. If you want the value of the form element to be included in the sequence string, the element must use the Name property.