Jquery.serializearray () function explanation

Source: Internet
Author: User
Tags javascript array

serializeArray()function is used to serialize a set of form elements and encode the contents of the form into a single JavaScript array .

serializeArray()Functions are commonly used to serialize the contents of a form into a JSON object, so that it is encoded in a JSON-formatted string.

The function encapsulates each form control that is available for submission as an object that has the name and Value property, the name of the form control, and the Value property. These object objects are then encapsulated as an array and returned.

The function does not serialize form controls that do not need to be submitted, which is consistent with the regular form submission behavior. For example: a form control that is not in a <form> tag is not committed, a form control without a name attribute is not committed, a form control with the disabled property is not committed, and a form control that is not selected is not committed.

Unlike regular form submissions, a regular form typically submits a button control with name, and the serializeArray() function does not serialize a button control with name. Please click here for more details.

The function belongs to an jQuery object (instance).

Grammar

JQuery 1.2 adds this function.

Jqueryobject.  Serializearray()   
return value

serializeArray()The return value of the function is the array type, which returns the JS array after the form element is encoded.

Example & Description
<form name= "MyForm" action= "http://www.365mini.com" method= "POST" > <input name= "UID" type= "hidden" value= "1" /> <input name= "username" type= "text" value= "Zhang San"/> <input name= "password" type= "text" value= "123456"/&    Gt <select name= "Grade" id= "grade" > <option value= "1" > First grade </option> <option value= "2" > Two years Grade </option> <option value= "3" selected= "selected" > Third grade </option> <option value= "4" > Grade IV & Lt;/option> <option value= "5" > Grade five </option> <option value= "6" > Six grade </option> < /select> <input name= "Sex" type= "Radio" checked= "Checked" value= "1"/> male <input name= "Sex" type= "Radio" V alue= "0"/> female <input name= "hobby" type= "checkbox" checked= "Checked" value= "1"/> swimming <input name= "hobby" ty pe= "checkbox" checked= "Checked" value= "2"/> Run <input name= "hobby" type= "checkbox" value= "3"/> Badminton <inpu T name= "btn" id= "bTN "type=" button "value=" click "/></form> 

Serialization of the <form> element allows you to serialize all the form elements within it directly.

var Formarray = $ ("form"). Serializearray ();/* The following is the contents of the serialized result array Formarray: [    {name: ' uid ', Value: ' 1 '},    {name: ' Us Ername ", Value:" Zhang San "},    {name:" Password ", Value:" 123456 "},    {name:" Grade ", Value:" 3 "},    {name:" Sex ", V Alue: "1"},    {name: "Hobby", Value: "1"},    {name: "Hobby", Value: "2"}];*/

We can also serialize some of the form elements directly.

var result = $ (": Text, select,: CheckBox"). Serializearray ();/* The following is the contents of the serialized results array Result: [     {name: "username", Value: " Zhang San "},     {name:" Password ", Value:" 123456 "},    {name:" Grade ", Value:" 3 "},    {name:" Hobby ", Value:" 1 "},
   {name: "Hobby", Value: "2"}];*/

Jquery.serializearray () function explanation

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.