Home > Web Front-end > JS Tutorial > body text

jquery序列化方法实例分析_jquery

WBOY
Release: 2016-05-16 15:55:53
Original
1416 people have browsed it

本文实例讲述了jquery序列化方法。分享给大家供大家参考。具体分析如下:

做ajax的时候,经常需要序列化,
serialize()只能序列化表单 。(注 : 表单里的内容 只能用 name )

现在有一个对象:

复制代码 代码如下:
var obj={a:1,b:2,c:3};

怎么让它序列化呢?
用prototype 可以用$H(obj).toQueryString() 搞定?jqueyr有什么方法吗?

答案是肯定的, jquery提供了 $.param()。

var obj={a:1,b:2,c:3};
var k = $.param(obj);
alert(k) // 输出 a=1&b=2&c=3

Copy after login

好了,去试试吧。。 ^_^。

serialize序列化的例子。。

1. jquery选择器选择表单中所有input(type为text和radio)
2. serialize()将其序列化

var msg = $("#innerbox input[type=text],#innerbox input[type=radio]").serialize();
$.ajax({
type: "POST",
url: "add.php",
data: msg,
success: function(data){ $(".showMsg").html(data); }
});

Copy after login

希望本文所述对大家的jQuery程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!