.serialize() 方法创建以标准 URL 编码表示的文本字符串。它的操作对象是代表表单元素集合的 jQuery 对象。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <title></title> <script src= "Scripts/jquery-1.4.1.js" type= "text/javascript" ></script> <script type= "text/jscript" > // $(function () { // alert($("form").serialize()); // }) function btnClick() { alert($( "form" ).serialize()); } </script> </head> <body> <form> <div><input type= "text" name= "a" value= "1" id= "a" /></div> <div><input type= "text" name= "b" value= "2" id= "b" /></div> <div><input type= "hidden" name= "c" value= "3" id= "c" /></div> <div> <textarea name= "d" rows= "8" cols= "40" >4</textarea> </div> <div><select name= "e" > <option value= "5" selected= "selected" >5</option> <option value= "6" >6</option> <option value= "7" >7</option> </select></div> <div> <input type= "checkbox" name= "f" value= "8" id= "f" /> </div> <div> <input type= "button" name= "g" value= "提交" id= "g" onclick= "btnClick()" /> </div> </form> </body> </html><span style= "font-size:18px;color:#ff0000;" > </span> |
点击提交:
输出标准的查询字符串:a=1&b=2&c=3&d=4&e=5
如果将复选框也选上的话 输出的就是:a=1&b=2&c=3&d=4&e=5&f=8