-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebforms.html
More file actions
163 lines (156 loc) · 7.22 KB
/
webforms.html
File metadata and controls
163 lines (156 loc) · 7.22 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="generator" content="gvim" />
<meta name="author" content="闲耘™ (hotoo.cn[AT]gmail.com)" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" media="all" />
<style type="text/css" media="screen">
.help-inline b{color:#f00; font-weight:bold; padding:2px 5px;}
</style>
<script type="text/javascript" src="utils.js" charset="utf-8"></script>
<script type="text/javascript" src="webforms.js" charset="utf-8"></script>
<title>WebForms</title>
</head>
<body>
<form class="form-horizontal" id="form-required">
<fieldset>
<legend>required</legend>
<div class="control-group">
<label class="control-label" for="input01">Text</label>
<div class="controls">
<input type="text" class="input-xlarge" id="input01" required />
<p class="help-inline"><b>*</b>required.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01">Password</label>
<div class="controls">
<input type="password" class="input-xlarge" id="input01" required />
<p class="help-inline"><b>*</b>required.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01">Single Checkbox</label>
<div class="controls">
<input type="checkbox" class="input-xlarge" id="input01" required />
<p class="help-inline"><b>*</b>required.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01">Group Checkbox</label>
<div class="controls">
<label class="checkbox" for="checkbox01">
<input type="checkbox" name="checkbox-group-required" class="input-xlarge" id="checkbox01" />
checkbox01</label>
<label class="checkbox" for="checkbox02">
<input type="checkbox" name="checkbox-group-required" class="input-xlarge" id="checkbox02" />
checkbox02</label>
<label class="checkbox" for="checkbox03">
<input type="checkbox" name="checkbox-group-required" class="input-xlarge" id="checkbox03" />
checkbox03</label>
<p class="help-inline"><b>*</b>required. must check more than one checkbox, but less than three.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01">Single Radio</label>
<div class="controls">
<input type="radio" name="radio-group-single" class="input-xlarge" id="input01" required />
<p class="help-inline"><b>*</b>required.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01">Group Checkbox</label>
<div class="controls">
<label class="radio" for="radio01">
<input type="radio" name="radio-group-required" class="input-xlarge" id="radio01" />
checkbox01</label>
<label class="radio" for="radio02">
<input type="radio" name="radio-group-required" class="input-xlarge" id="radio02" required />
checkbox02</label>
<label class="radio" for="radio03">
<input type="radio" name="radio-group-required" class="input-xlarge" id="radio03" />
checkbox03</label>
<p class="help-inline"><b>*</b>required.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01">Email</label>
<div class="controls">
<input type="email" class="input-xlarge" id="input01" required />
<p class="help-inline"><b>*</b>required.</p>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save changes</button>
<button class="btn" type="reset">Cancel</button>
</div>
</fieldset>
</form>
<form action="webforms.html" method="get" accept-charset="utf-8" id="f">
required: <input type="text" name="required" value="" required error-message="必填项" /><br/>
date start: <input type="date" name="datestart" id="datestart" value="" required data-format="YYYY/MM/DD" error-message="请输入合法的日期" /><br/>
date end: <input type="date" name="dateend" value="" data-format="YYYYMMDD" required error-message="请输入合法的日期" /><br/>
date start: <input type="date" name="datestart" id="datestart" value="" pattern="^\d{4}(?:0[1-9]|1[0-2])(?:0[1-9]|[12][0-9]|3[01])$" error-message="请输入合法的日期" /><br/>
date end: <input type="date" name="dateend" value="" pattern="^\d{4}(?:0[1-9]|1[0-2])(?:0[1-9]|[12][0-9]|3[01])$" error-message="请输入合法的日期" /><br/>
number: <input type="number" name="number" value="" error-message="请输入合法的数值" /><br/>
url: <input type="url" name="url" value="" error-message="请输入正确的 URL 地址" /><br/>
email: <input type="email" name="email" value="" error-message="请输入正确的 Email 地址。" /><br/>
alipay email: <input type="email" pattern="@alipay\.com$" error-message="请使用支付宝邮箱" name="" value="" /><br/>
alipay emails: <textarea name="emails" rows="8" cols="40" required pattern="^\s*\w+(?:\.\w+)*@alipay\.com(\s*;\s*\w+(?:\.\w+)*@alipay\.com)*\s*$" error-message="请使用支付宝邮箱,以英文逗号分隔。"></textarea><br/>
<p><input type="submit" value="Continue →"></p>
</form>
<script type="text/javascript">/*<![CDATA[*/
function $(id){return document.getElementById(id);}
new WebForms($("form-required"), {
rules: {
"checkbox-group-required": function(elem){
var form = elem.form,
name = elem.name;
if(!form){return;}
var items = form[name], count=0;
for(var i=0,l=items.length; i<l; i++){
if(items[i].checked){count++;}
}
if(count<1 || count>2){return false;}
return true;
}
},
feedback: function(elem){
}
});
new WebForms(document.getElementById("f"),{
rules: {
"datestart": function(elem){
var now = new Date(),
format = elem.getAttribute("data-format")||"YYYY/MM/DD",
val = Date.parse(elem.value, format);
if(!val){return false;}
return now.getFullYear() < val.getFullYear() ||
now.getMonth() < val.getMonth() ||
now.getDate() < val.getDate();
},
"dateend": function(elem){
var datestart = document.getElementById("datestart"),
start_format = datestart.getAttribute("data-format")||"YYYY/MM/DD",
start = Date.parse(datestart.value, start_format),
end_format = elem.getAttribute("data-format") || "YYYY/MM/DD",
end = Date.parse(elem.value, end_format);
if(!start){return false;}
if(!end){return false;}
return start.getFullYear() < end.getFullYear() &&
start.getMonth() < end.getMonth() &&
start.getDate() < end.getDate();
}
},
feedback: function(elem){
alert(elem.getAttribute("error-message"));
}
});
/*]]>*/</script>
</body>
</html>