获取页面中指定表单的所有控件值。
表单序列化后的字符串,其格式如:username=%E5%95%8A%E8%94%A1&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=%E5%95%8A%E8%94%A1&password=123456&interest=music&interest=sport&interest=dance®time=Thu%2C%2027%20Sep%202007%2008%3A35%3A55%20UTC。
//注意里面的同名表单
}
</script>