1
- module ( 'baidu.form.serialize ' ) ;
1
+ module ( 'baidu.form.json ' ) ;
2
2
function createForm ( ) {
3
3
var div , form , text1 , text2 , hid , cb1 , cb2 , rb1 , rb2 , pass , textArea , sel , selmul , button ;
4
4
div = document . createElement ( 'div' ) ;
@@ -8,12 +8,16 @@ function createForm() {
8
8
9
9
text1 = document . createElement ( 'input' ) ;
10
10
text2 = document . createElement ( 'input' ) ;
11
+ text3 = document . createElement ( 'input' ) ;
12
+ text4 = document . createElement ( 'input' ) ;
11
13
hid = document . createElement ( 'input' ) ;
12
14
rb1 = document . createElement ( 'input' ) ;
13
15
rb2 = document . createElement ( 'input' ) ;
14
16
cb1 = document . createElement ( 'input' ) ;
15
17
cb2 = document . createElement ( 'input' ) ;
18
+ cb3 = document . createElement ( 'input' ) ;
16
19
pass = document . createElement ( 'input' ) ;
20
+ bu = document . createElement ( 'input' ) ;
17
21
textArea = document . createElement ( 'textarea' ) ;
18
22
sel = document . createElement ( 'select' ) ;
19
23
selmul = document . createElement ( 'select' ) ;
@@ -23,46 +27,63 @@ function createForm() {
23
27
document . body . appendChild ( div ) ;
24
28
25
29
text1 . type = "text" ;
26
- text1 . disabled = "disabled " ;
30
+ text1 . name = "disable " ;
27
31
text1 . value = "disable" ;
32
+ text1 . disabled = "disabled" ;
28
33
29
34
text2 . type = "text" ;
30
- text2 . value = "param&1" ;
31
35
text2 . name = "param1" ;
36
+ text2 . value = "param&1 测试中文" ;
37
+ text3 . type = "text" ;
38
+ text3 . name = "param2" ;
39
+ text3 . value = "" ;
40
+ text4 . type = "text" ;
41
+ text4 . value = "param3" ;
32
42
33
43
hid . type = "hidden" ;
34
- hid . name = "param2 " ;
35
- hid . value = "param2 " ;
44
+ hid . name = "hidden3 " ;
45
+ hid . value = "hidden3 " ;
36
46
37
47
form . appendChild ( text1 ) ;
38
48
form . appendChild ( text2 ) ;
49
+ form . appendChild ( text3 ) ;
50
+ form . appendChild ( text4 ) ;
39
51
form . appendChild ( hid ) ;
40
52
41
53
rb1 . type = "radio" ;
42
- rb1 . value = "rb1" ;
43
54
rb1 . name = "rb" ;
55
+ rb1 . value = "rb1" ;
44
56
rb2 . type = "radio" ;
45
- rb2 . value = "rb2" ;
46
57
rb2 . name = "rb" ;
47
- cb1 . name = "cb " ;
58
+ rb2 . value = "rb2 " ;
48
59
cb1 . type = "checkbox" ;
60
+ cb1 . name = "cb" ;
49
61
cb1 . value = "cb1" ;
50
- cb2 . name = "cb" ;
51
62
cb2 . type = "checkbox" ;
63
+ cb2 . name = "cb" ;
52
64
cb2 . value = "cb2" ;
65
+ cb3 . type = "checkbox" ;
66
+ cb3 . name = "cb" ;
67
+ cb3 . value = "cb3" ;
53
68
54
69
form . appendChild ( cb1 ) ;
55
70
form . appendChild ( cb2 ) ;
71
+ form . appendChild ( cb3 ) ;
56
72
form . appendChild ( rb1 ) ;
57
73
form . appendChild ( rb2 ) ;
58
74
59
75
rb2 . checked = true ;
60
76
cb1 . checked = true ;
77
+ cb3 . checked = true ;
61
78
62
79
pass . type = "password" ;
63
- pass . value = "pwd" ;
64
80
pass . name = "pwd" ;
81
+ pass . value = "pwd" ;
65
82
83
+ bu . type = "button" ;
84
+ bu . name = "bu" ;
85
+ bu . value = "bu1" ;
86
+
66
87
textArea . name = "ta" ;
67
88
textArea . value = "textarea" ;
68
89
@@ -72,8 +93,8 @@ function createForm() {
72
93
sel . options [ sel . options . length ] = new Option ( '3' , '3' ) ;
73
94
sel . options [ 2 ] . selected = "selected" ;
74
95
75
- selmul . name = "selmul" ;
76
- selmul . multiple = "multiple" ;
96
+ selmul . name = "selmul" ;
97
+ selmul . multiple = "multiple" ;
77
98
if ( selmul . type != 'select-multiple' ) {
78
99
selmul = document . createElement ( '<select name="selmul" multiple="true"></select>' ) ;
79
100
}
@@ -86,9 +107,11 @@ function createForm() {
86
107
selmul . options [ 2 ] . selected = "selected" ;
87
108
88
109
button . id = "sub" ;
110
+ button . name = "sub" ;
89
111
button . value = "提交" ;
90
112
91
113
form . appendChild ( pass ) ;
114
+ form . appendChild ( bu ) ;
92
115
form . appendChild ( textArea ) ;
93
116
form . appendChild ( sel ) ;
94
117
form . appendChild ( selmul ) ;
@@ -97,6 +120,21 @@ function createForm() {
97
120
}
98
121
99
122
test ( "传入form,返回结果" , function ( ) {
123
+ expect ( 13 ) ;
100
124
var f = createForm ( ) ;
101
- baidu . form . serialize ( f ) ;
125
+ var j = baidu . form . serialize ( f ) ;
126
+ equals ( j . length , 12 , "12 arears" ) ;
127
+ equals ( j [ 0 ] , "param1=param%261%20测试中文" , "The text input(escapeUrl) is right" ) ;
128
+ equals ( j [ 1 ] , "param2=" , "The text input(no value) is right" ) ;
129
+ equals ( j [ 2 ] , "hidden3=hidden3" , "The text input(hidden) is right" ) ;
130
+ equals ( j [ 3 ] , "cb=cb1" , "The combox is right" ) ;
131
+ equals ( j [ 4 ] , "cb=cb3" , "The combox is right" ) ;
132
+ equals ( j [ 5 ] , "rb=rb2" , "The radio is right" ) ;
133
+ equals ( j [ 6 ] , "pwd=pwd" , "The password is right" ) ;
134
+ equals ( j [ 7 ] , "ta=textarea" , "The textarea is right" ) ;
135
+ equals ( j [ 8 ] , "sel=3" , "The select is right" ) ;
136
+ equals ( j [ 9 ] , "selmul=1" , "The selmul is right" ) ;
137
+ equals ( j [ 10 ] , "selmul=2" , "The selmul is right" ) ;
138
+ equals ( j [ 11 ] , "selmul=3" , "The selmul is right" ) ;
139
+ $ ( f ) . remove ( ) ;
102
140
} ) ;
0 commit comments