Jquery-serialize () The way to output serialized form form Values _jquery

Source: Internet
Author: User
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&gt, <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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.