-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdemo.html
179 lines (168 loc) · 4.83 KB
/
demo.html
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body, p, form{
margin: 0;
}
.sign-up{
width: 328px;
color: #505050;
margin-left: 20px;
}
.sign-up label{
line-height: 150%;
display: block;
margin-top: 20px;
}
.sign-up input{
width: 100%;
padding: 0 15px;
height: 30px;
border: 1px solid #c8c8c8;
border-radius: 2px;
font-size: 14px;
font-family: "Lato Regular";
box-sizing: border-box;
}
.sign-up input.invalid {
border: 1px solid #f47575;
}
.sign-up input:focus{
outline: none;
border: 1px solid #38cb7b;
}
.sign-up input[type=submit]{
width: 100%;
background-color: #41ca7e;
height: 40px;
color: #fff;
font-size: 18px;
margin: 30px 0 30px 0;
cursor: pointer;
border-radius: 2px;
}
.error{
position: absolute;
border: 1px solid #f0f0f0;
border-radius: 5px;
padding: 15px 10px;
background-color: white;
font-size: 14px;
color: #282828;
box-shadow: 0 0 20px #282828;
}
.error:after{
content: "";
position: absolute;
top: -8px;
left: 10px;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid white;
}
.error:after{
content: "";
position: absolute;
top: -8px;
left: 10px;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid white;
}
.error:before{
content: "!";
display: inline-block;
background-color: rgb(250,168,50);
font-size: 16px;
width: 18px;
height: 18px;
line-height: 18px;
color: white;
border-radius: 2px;
text-align: center;
margin-right: 5px;
margin-bottom: 5px;
vertical-align: middle;
}
.error span{
display: inline-block;
vertical-align: top;
line-height: 18px;
}
</style>
</head>
<body>
<form class="sign-up">
<label>邮箱地址</label>
<input type="email" name="account" t="email" required="">
<label>密码</label>
<input type="password" name="password" pattern=".{6,20}" pm="密码要在6到20位之间" required="">
<label>确认密码</label>
<input type="password" name="confirm-pwd">
<input id="confirm-sign" type="submit" value="注册">
<p></p>
</form>
<script src="http://s.xnimg.cn/ajax/zepto/zepto-1.1.0.all.min.js"></script>
<!--
<script src="./jquery-1.11.3.min.js "></script>
-->
<script src="./checkValidity.js"></script>
<script>
!function(){
var checkAccountExist = false;
function submit(){
console.log("表单验证成功,准备提交");
}
newFormCheck($(".sign-up")[0], checkAccountExist, submit);
}();
function checkAccountExist(failCallback, successCallback){
var input = this;
util.ajax("/register/hasUser", {account: this.value}, function(data){
if(data.isUser === true){
failCallback();
}
else{
successCallback();
}
});
}
function checkPwdIdentity(){
if(this.form["password"].value !== this.form["confirm-pwd"].value){
return false;
}
return true;
}
function newFormCheck(form, checkAccountExist, submitHandler){
var checkRule = {
"confirm-pwd": {
check: checkPwdIdentity,
msg: "两次密码输入不一致"
}
};
if(checkAccountExist){
checkRule.account = {
check: checkAccountExist,
msg: "账户已存在!",
async: true
};
}
if(checkAccountExist){
checkRule.account = {
check: checkAccountExist,
msg: "账号已存在",
async: true
};
}
return new Form(form, {
errorMsgClass: "error", //错误提示框的类,用于自定义样式
errorInputClass: "invalid", //input无效的类名,用于自定义样式
rule: checkRule,
lang: "cn",
disableBrowserMsg: !(navigator.language || navigator.userLanguage).match(/cn/i)
}, submitHandler);
}
</script>
</body>
</html>