Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use jQuery.param

Shulou Source: shulou.com Published: 2022-06-01 07:35:02 10月17日 Update

This article mainly explains "how to use jQuery.param". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use jQuery.param.

The input element is also a serialized element in jQuery 1.4 HTML5.

We can display a query string for an object and a corresponding URI-decoded version, as follows:

Var myObject = {

A: {

One: 1

Two: 2

Three: 3

}

B: [1,2,3]

}

Var recursiveEncoded = $.param (myObject)

Var recursiveDecoded = decodeURIComponent ($.param (myObject))

Alert (recursiveEncoded)

Alert (recursiveDecoded)

The results of recursiveEncoded and recursiveDecoded are as follows:

A%5Bone%5D=1&a%5Btwo%5D=2&a%5Bthree%5D=3&b%5B%5D=1&b%5B%5D=2&b%5B%5D=3

A [one] = 1 & a [two] = 2 & a [three] = 3 [] = 1 [] = 2 [] = 3

Before jQuery1.4, to mimic the behavior of $.param (), we can set the traditional parameter to true:

Var myObject = {

A: {

One: 1

Two: 2

Three: 3

}

B: [1,2,3]

}

Var shallowEncoded = $.param (myObject, true)

Var shallowDecoded = decodeURIComponent (shallowEncoded)

Alert (shallowEncoded)

Alert (shallowDecoded)

The results of shallowEncoded and shallowDecoded are as follows:

A=%5Bobject+Object%5D&b=1&b=2&b=3

A = [object + Object] & b=1&b=2&b=3

Example:

Example: serialize a key/value object. / span >

Div {color:red;}

Var params = {width:1680, height:1050}

Var str = jQuery.param (params)

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

Demo:

Example: serial number of some complex objects

/ / = 1.4:

$.param ({a: [2helm 3jue 4]}) / / "a [] = 2yoga [] = 3beaua [] = 4"

/ / = 1.4:

$.param ({a: {bburet 1 magnificent cjoun 2}, d: [3pr 4, {evision 5}]}) / / "a [b] = 1 & a [c] = 2d [] = 3d [] = 4fud [2] [e] = 5"

At this point, I believe you have a deeper understanding of "how to use jQuery.param". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Object sequence element content result learning query complex practical deeper example interest parameter character string practicality actual serial number simple operation method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Shulou Information Shulou Technology NVidia