Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use serialize () in jQuery

Shulou Source: shulou.com Published: 2022-06-01 07:34:32 09月14日 Update

This article is about how to use serialize() in jQuery. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

jQuery successfully serializes control forms. Only form elements check the input boxes they contain; in all other cases, input elements to serialize should be part of a collection passed to the.serialize() method. Selecting strings in which a form and its child elements are serialized in a collection results in duplication.

Note: Only "successful controls" can be serialized into strings. The value of the submit button is not serialized. In addition, if you want the value of a form element to be serialized into a string, the element must contain a name attribute. In addition, checkbox and radio button (input type "radio" or "checkbox") values are serialized only when selected. In addition, the data for file selection elements is not serialized.

Examples:

Serialize a form into a query string that can be sent in an Ajax request.

body, select { font-size:12px; }

form { margin:5px; }

p { color:red; margin:5px; font-size:14px; }

b { color:blue; }

Single

Single2

Multiple

Multiple2

Multiple3

check1

check2

radio1

radio2

function showValues() {

var str = $("form").serialize();

$("#results").text(str);

}

$(":checkbox, :radio").click(showValues);

$("select").change(showValues);

showValues();

Thank you for reading! About "serialize() in jQuery how to use" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Sequence element character form only string content button more article input selection good practical success example attribute situation data file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple OPPO Reno Docker macOS