-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.html
307 lines (299 loc) · 11.6 KB
/
register.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册-闲言</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="res/layui/css/layui.css">
<link rel="stylesheet" href="res/static/css/mian.css">
<link href="http://cdn.bootcss.com/twitter-bootstrap/2.0.4/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="res/static/css/register.css">
</head>
<body class="lay-blog">
<div class="bg">
<div class="bg-wrap">
</div>
</div>
<div class="container-wrap">
<div class="container">
<div class="contar-wrap">
<form class="form-horizontal log-form">
<fieldset>
<div id="legend" class="log-head">
<legend class="">个人资料</legend>
</div>
<div class="control-group">
<label class="control-label">邮箱</label>
<div class="controls">
<div class="input-append">
<input class="span2 email" placeholder="请输入邮箱地址" type="email">
</div>
<p class="help-block">邮箱的正确格式为 [email protected]</p>
</div>
</div>
<div class="control-group">
<label class="control-label">密码</label>
<div class="controls">
<input type="password" placeholder="请设置您的密码" class="input-xlarge pwd1">
<p class="help-block">密码由6至16位大小写字母或数字组成</p>
</div>
</div>
<div class="control-group">
<label class="control-label">确认密码</label>
<div class="controls">
<input type="password" placeholder="请再次输入您设置的密码" class="input-xlarge pwd2">
<p class="help-block">确认您的密码同上一次一致</p>
</div>
</div>
<div class="control-group">
<label class="control-label">昵称</label>
<div class="controls">
<input type="text" placeholder="请输入您的昵称" class="input-xlarge nickname">
<p class="help-block">用户名由1-8位不含空格的字符组成</p>
</div>
</div>
<div class="control-group ">
<label class="control-label">性别</label>
<div class="controls sex">
<label class="radio inline">
<input type="radio" value="男" name="sex">
男
</label>
<label class="radio inline">
<input type="radio" value="女" name="sex">
女
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">年龄</label>
<div class="controls">
<input type="number" placeholder="请输入您的年龄" class="input-xlarge age">
<p class="help-block">年龄的输入范围在1-120</p>
</div>
</div>
<div class="control-group">
<label class="control-label">星座</label>
<div class="controls">
<select class="input-xlarge xinzuo">
<option>请选择星座</option>
<option>白羊座</option>
<option>金牛座</option>
<option>双子座</option>
<option>巨蟹座</option>
<option>狮子座</option>
<option>处女座</option>
<option>天秤座</option>
<option>天蝎座</option>
<option>射手座</option>
<option>摩羯座</option>
<option>水瓶座</option>
<option>双鱼座</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">个性签名</label>
<div class="controls ">
<div class="textarea">
<textarea type="" class="motto"> </textarea>
</div>
</div>
</div>
<div>
<label class="control-label"></label>
<div class="controls">
<span class="sub-button">注册</span>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<div class="footer">
<p>
<span>© 2019</span>
<span><a href="http://www.layui.com" target="_blank">浙江大学软件学院</a></span>
<span>S403</span>
</p>
<p><span>人生就是一场修行,祝君猪事顺利</span></p>
</div>
<script src="res/layui/layui.js"></script>
<script>
layui.config({
base: 'res/static/js/'
}).use('blog');
</script>
<script src="res/jquery/jquery-1.12.4.js"></script>
<script>
//邮箱的验证
let email;
let $email= $('.email');
//进入填写页面,焦点落在第一行
$email.focus();
$email.change(function () {
email = $email.val();
});
$email.on('blur', function () {
let reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
if (reg.test(email)) {
$.ajax({
url:'http://47.100.226.85:8080/find-friends/user/validemail',
type: 'post',
data:email,
success:function (data) {
if(!data){
alert("您注册的邮箱地址已经被使用!");
$email.parents('.control-group').attr('class','error control-group');
$email.val('');
email ='';
}
else {
$email.parents('.control-group').attr('class','success control-group');
}
},
contentType: "application/json",
});
} else {
$email.val('');
$email.parents('.control-group').attr('class','error control-group');
}
});
//密码的验证
let $pwd1 = $('.pwd1'), $pwd2 = $('.pwd2');
let pwd1=$pwd1.val(), pwd2 = $pwd2.val();
$pwd1.change(function () {
pwd1 = $pwd1.val();
});
$pwd2.change(function () {
pwd2 = $pwd2.val();
});
$pwd1.on('blur', function () {
let reg = /^[\w]{6,16}$/;
if (reg.test(pwd1)) {
$pwd1.parents('.control-group').attr('class','success control-group');
}
else {
$pwd1.val('');
$pwd1.parents('.control-group').attr('class','error control-group');
}
});
$pwd2.on('blur', function () {
let reg = /^[\w]{6,16}$/;
if (!reg.test(pwd2)) {
$pwd2.val('');
$pwd2.parents('.control-group').attr('class','error control-group')
}
else if(pwd1 !== pwd2) {
$pwd1.val('');
$pwd2.val('');
$pwd2.parents('.control-group').attr('class','error control-group');
$pwd1.parents('.control-group').attr('class','error control-group')
}
else{
$pwd2.parents('.control-group').attr('class','success control-group');
}
});
//用户名的验证
let nickname;
let $nickname = $('.nickname');
$nickname.change(function () {
nickname = $.trim($nickname.val());
});
$nickname.on('blur', function () {
if (!nickname || nickname.length > 8) {
$nickname.val('');
$nickname.parents('.control-group').attr('class','error control-group');
}
else{
$nickname.parents('.control-group').attr('class','success control-group');
}
});
//年龄的验证
let age;
let $age = $('.age');
$age.change(function () {
age = $age.val();
});
$age.on('blur',function () {
let reg= /^(?:[1-9][0-9]?|1[01][0-9]|120)$/;
if(!reg.test(age)){
$age.parents('.control-group').attr('class','error control-group');
$age.val('');
}
else{
$age.parents('.control-group').attr('class','success control-group');
}
});
//星座的选取
let $xinzuo = $('.xinzuo');
let xinzuo = $xinzuo.val();
/*if(xinzuo =='请选择星座'){
$xinzuo.parents('.control-group').attr('class','error control-group');
}*/
$xinzuo.change(function () {
xinzuo = $xinzuo.val();
});
$xinzuo.on('blur',function () {
if(xinzuo!=='请选择星座'){
$xinzuo.parents('.control-group').attr('class','success control-group');
}
else if(xinzuo =='请选择星座'){
$xinzuo.parents('.control-group').attr('class','error control-group');
}
});
//个性签名设置
let $motto = $('.motto');
let motto;
$motto.change(function () {
motto = $motto.val();
});
$motto.on('blur',function () {
$motto.parents('.control-group').attr('class','success control-group');
});
//性别的选取
let sex = $("input:radio[name='sex'][checked='checked']").attr('value');
$("input:radio[name='sex']").on('click',function () {
$(this).attr('checked','checked');
$(this).parent().siblings().children('input').removeAttr('checked');
let $sex= $("input:radio[name='sex'][checked='checked']");
sex= $sex.attr('value');
$sex.parents('.control-group').attr('class','success control-group');
});
$('.sub-button').on('click',function () {
// 表单内全部input添加success类才能填写通过
if($('.success').length < 8 ){
alert('抱歉,还有内容没有填写通过!')
}
else{
let userInfo= {
email:email,
password:pwd1,
nickname:nickname,
motto:motto,
sex:sex,
age:age,
xinzuo:xinzuo
};
$.ajax({
url:'http://47.100.226.85:8080/find-friends/user/register',
type:'post',
data:JSON.stringify(userInfo),
success: function(state){
if( state == 'success'){
if(confirm('注册成功,是否跳转到登录界面?')){
window.location.href = 'login.html';
}
}
else {
alert('failed register')
}
},
contentType: "application/json",
});
}
});
</script>
</body>
</html>