When verifying a form, you often need to obtain the value of the name & amp; #39; *** & amp; #39; element in the form and then judge it. JQuery provides jQuery. serizlizeArray to serialize a form into an array. However, arrays are not convenient for us to operate. I need to serialize the form into a pair... when SyntaxHig verifies a form, it is often necessary to obtain the value of the element name = '***' in the form and then judge it. JQuery provides jQuery. serizlizeArray to serialize a form into an array. However, arrays are inconvenient for us to operate. I need to serialize a form into an object. This makes it easier for us to operate.
The following code is used:
View plaincopy to clipboardprint?
/**
* @ Author gaohuia
* @ Site http://www.zeroplace.cn/
*/
(Function ($ ){
$. Fn. extend ({
SerializeObject: function (){
If (this. length> 1 ){
Return false;
}
Var arr = this. serializeArray ();
Var obj = new Object;
$. Each (arr, function (k, v ){
Obj [v. name] = v. value;
});
Return obj;
}
});
}) (JQuery );
/**
* @ Author gaohuia
* @ Site http://www.zeroplace.cn/
*/
(Function ($ ){
$. Fn. extend ({
SerializeObject: function (){
If (this. length> 1 ){
Return false;
}
Var arr = this. serializeArray ();
Var obj = new Object;
$. Each (arr, function (k, v ){
Obj [v. name] = v. value;
});
Return obj;
}
});
}) (JQuery );
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