For more information about jquery form serialization, see jquery serialization.

Source: Internet
Author: User

For more information about jquery form serialization, see jquery serialization.

This article mainly introduces some precautions for jquery form serialization. We will share the notes for your reference and learning. I will not talk about them here. Let's take a look at the details:

Let's talk about the differences between readonly and disabled in the form:

Readonly is only valid for input and textarea, but disabled is valid for all form elements, including radio and checkbox.
If disabled is used in the form, the user cannot select it. That is to say, this text box cannot get the focus, while readonly can get the focus, but cannot be modified. It is read-only.

Most importantly, when sending a form, the form control property does not have the name attribute. This field is not sent, nor does it form a key-value pair. The Form Control property is disabeld, this field will not be sent, nor will it form a key-Value Pair

Test 1. The name attribute is not set:

<Body> <form id = "form1"> <select> <option value = "0"> huluwa test 0 </option> <option value = "1"> huluwa Test 1 </option> <option value = "2"> huluwa Test 2 </option> </select> <input type = "button" id = "btnSubmit" value = "Submit" name = "btnSubmit"/> </form> <script type = "text/javascript" >$ (document ). ready (function () {$ ("# btnSubmit "). click (function () {console. log ("serialize:"); console. log ($ ("# form1 "). serialize (); console. log ("serializeArray:"); console. log ($ ("# form1 "). serializeArray () ;};}); </script> </body>

The output result is as follows:

serialize: serializeArray:[]length: __proto__: Array(0)

Test 2: Set the name attribute:

<Body> <form id = "form1"> <select name = "selectHuLuWa"> <option value = "0"> huluwa test 0 </option> <option value = "1 "> huluwa Test 1 </option> <option value =" 2 "> huluwa Test 2 </option> </select> <input type =" button "id =" btnSubmit" value = "Submit" name = "btnSubmit"/> </form> <script type = "text/javascript"> $ (document ). ready (function () {$ ("# btnSubmit "). click (function () {console. log ("serialize:"); console. log ($ ("# form1 "). serialize (); console. log ("serializeArray:"); console. log ($ ("# form1 "). serializeArray () ;};}); </script> </body>

The output result is as follows:

serialize: selectHuLuWa=0 serializeArray: [{…}]{name: "selectHuLuWa", value: "0"}length:1__proto__:Array(0)

Test 3. Set the readoly attribute:

<Body> <form id = "form1"> <select name = "selectHuLuWa" readonly = "readonly"> <option value = "0"> huluwa test 0 </option> <option value = "1"> huluwa Test 1 </option> <option value = "2"> huluwa Test 2 </option> </select> <input type = "button" id = "btnSubmit" value = "Submit" name = "btnSubmit"/> </form> <script type = "text/javascript" >$ (document ). ready (function () {$ ("# btnSubmit "). click (function () {console. log ("serialize:"); console. log ($ ("# form1 "). serialize (); console. log ("serializeArray:"); console. log ($ ("# form1 "). serializeArray () ;};}); </script> </body>

The test results are as follows:

Test 4. Set the disabled attribute

<Body> <form id = "form1"> <select name = "selectHuLuWa" disabled = "disabled"> <option value = "0"> huluwa test 0 </option> <option value = "1"> huluwa Test 1 </option> <option value = "2"> huluwa Test 2 </option> </select> <input type = "button" id = "btnSubmit" value = "Submit" name = "btnSubmit"/> </form> <script type = "text/javascript" >$ (document ). ready (function () {$ ("# btnSubmit "). click (function () {console. log ("serialize:"); console. log ($ ("# form1 "). serialize (); console. log ("serializeArray:"); console. log ($ ("# form1 "). serializeArray () ;};}); </script> </body>

The test results are as follows:

As a result, the form control does not have the name attribute, and the disabled attribute cannot be serialized.

** If you need to serialize disabled, the method is:

Remove the disabled Attribute before serialization. After serialization, add it. **

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message to us. Thank you for your support.

Related Article

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.