$.Form.serialize( NameValuePair )应用介绍



$.Form.serialize( NameValuePair )

虚拟一个表单,并设置表单控件名与值。
参数
NameValuePair
必选项。设置虚拟的表单控件。该参数形式为:{ name1=value, name2=value2, ……}
返回值
虚拟表单序列化后的字符串,其格式如:username=啊蔡&password=123456
描述
表单中如有 disabled=true 或者没有 name 属性的控件将被忽略。同名控件将发送一组同名但不同值的字符串。该方法通常用于 Ajax 的提交参数(parameters)。
示例
<form method=”post” name=”reg” action=”http://localhost”>
<input type=”text” name=”username” />
<input type=”password” name=”password” />
<input type=”checkbox” name=”interest” value=”music” /> //新用户兴趣爱好调查,勾选
<input type=”checkbox” name=”interest” value=”sport” /> //勾选
<input type=”checkbox” name=”interest” value=”dance” /> //勾选
<input type=”submit” value=”用户注册” />
<input type=”button” value=”用JavaScript提交表单” onclick=”test()” />
</form>
<script type=”text/javascript” >
function test(){
alert( $.Form(“reg”).serialize( { regTime:new Date().toGMTString()} ) ); //serizlize 方法补充了一个时间控件,控件的name=regTime,值为当前时间。

//username=啊蔡&password=123456&interest=music&interest=sport&interest=dance&regtime=Thu, 27 Sep 2007 08:35:55 UTC。
//注意里面的同名表单
}
</script>
*************************************************************************************************
说明
将一个表单序列化
使用
XN.FORM.serialize(form,type)
form 一个表单的id或者引用
type 序列化之后返回的形式,默认为’string’
‘string’返回一个url参数形式的字符串
‘array’ 返回一个数组
依赖文件
<script type=”text/javascript” src=”http://static.xiaonei.com/js/xn.core.js”></script> <script type=”text/javascript” src=”http://static.xiaonei.com/js/xn.form.js”></script>