简单的注册页面

简单的注册页面

七月 17, 2019 阅读数(请刷新)

写了个HTML+JS注册页面

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>会员注册</title>
<style>
tr>td:nth-child(1){
text-align: right;
}
tr>td:nth-child(2){
text-align: left;
}
tr>td:nth-child(3){
text-align: left;

}
div{
width:700px;
height: 600px;
background-color:rgb(255,238,211) ;
position: absolute;
left: 25%;
top: 10%;
}
p{
padding: 0;
margin: 0;
color: red;
}
</style>
<script>
var sum = 0;
function f(t) {

switch (t) {
case 1: var username = document.getElementById("t1").value;

if(username.length<6||username.length>16){

var str1 = "用户名不是6-16位,请核对后再次输入!";

document.getElementById("c1").innerText=str1;
document.getElementById("t1").value="";
}
else {
if (username.substr(0,1)==="$"||username.substr(0,1)==="_") {
str1 = "√";
sum++;
document.getElementById("c1").innerText = str1;
}else{
str1 = "用户名不是以$或_开头";
document.getElementById("c1").innerText = str1;
document.getElementById("t1").value="";
}
}
if(sum===5){
document.getElementById("sub").disabled=false;
}
break;
case 2: var password = document.getElementById("t2").value;

if(password.length<6||password.length>16){

var str2 = "密码不是6-16位,请核对后再次输入!";

document.getElementById("c2").innerText=str2;
document.getElementById("t2").value="";
}
else {
if (/^[A-Z]+$/.test(password.substr(0,1))) {
str2 = "√";
sum++;
document.getElementById("c2").innerText = str2;
}
else{
str2 = "密码以大写字母开头,请核对后再次输入!";

document.getElementById("c2").innerText=str2;
document.getElementById("t2").value="";
}
}
if(sum===5){
document.getElementById("sub").disabled=false;
}
break;
case 3: var cpassword = document.getElementById("t3").value;
var psd = document.getElementById("t2").value;
if(cpassword.length===0){
var str3 = "密码不能为空";
document.getElementById("c3").innerText = str3;
}
else{
if(psd===cpassword){

str3 = "√";
sum++;
document.getElementById("c3").innerText = str3;
}
else {
str3 = "两次密码不同!";
document.getElementById("c3").innerText = str3;
document.getElementById("t3").value="";
}
}
if(sum===5){
document.getElementById("sub").disabled=false;
}
break;

case 4: var identity = document.getElementById("t4").value;

if(identity.length===18){

var str4 = "√";
sum++;

document.getElementById("c4").innerText = str4;
}
else {
str4 = "身份证号不正确!";
document.getElementById("c4").innerText = str4;
document.getElementById("t4").value="";
}
if(sum===5){

document.getElementById("sub").disabled=false;
}
break;
case 5: var age = document.getElementById("t5").value;

if(age<0||age>128){

var str5 = "年龄错误!";
document.getElementById("c5").innerText = str5;
document.getElementById("t5").value="";
}
else {
var str5 = "√";
sum++;

document.getElementById("c5").innerText = str5;
}
if(sum===5){

document.getElementById("sub").disabled=false;
}
break;


}
}
function re(){
document.getElementById("c1").innerText="只能以$_或字母开头6-16位字母或数字组合";
document.getElementById("c2").innerText="必须以大写字母开头6-16位字母或者数字组合";
document.getElementById("c3").innerText="请再次确认密码";
document.getElementById("c4").innerText="请输入正确的身份证号,以便核实您的信息";
}
function success(){
alert("注册成功!")
}
</script>
</head>
<body>
<div align="center">

<form method="get">
<table>
<caption>
<h1>会员注册</h1>
</caption>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" required onblur="f(1)" id="t1"></td>
<td>
<p id="c1">只能以$_或字母开头6-16位字母或数字组合</p>
</td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" required onblur="f(2)" id="t2"></td>
<td>
<p id="c2">必须以大写字母开头6-16位字母或者数字组合</p>
</td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="password" name="cpassword" required onblur="f(3)" id="t3"></td>
<td>
<p id="c3">请再次确认密码</p>
</td>
</tr>
<tr>
<td> 姓名:<br></td>
<td><input type="text" name="name" required></td>
<td></td>
</tr>
<tr>
<td> 年龄:</td>
<td><input type="number" name="age" required onblur="f(5)" id="t5"></td>
<td>
<p id="c5"></p>
</td>
</tr>
<tr>
<td> 性别:</td>
<td><input type="radio" name="sex" value="m" checked>男 <input type="radio" name="sex" value="f">女</td>
<td></td>
</tr>
<tr>
<td>身份证号:</td>
<td><input type="text" name="identity" required onblur="f(4)" id="t4"></td>
<td>
<p id="c4">请输入正确的18位身份证号,以便核实您的信息</p>
</td>
</tr>
<tr>
<td>出生年月:</td>
<td><input type="date" name="birthday" required></td>
<td></td>
</tr>
<tr>
<td>居住地址:</td>
<td>
<select id="one" name="address1" onchange="func(this.value)">
<option value="">--城市--</option>
<option value="0">四川省</option>
<option value="1">山西省</option>
<option value="2">陕西省</option>
</select>
<select id="two" name="address2">
<option value="">--区县--</option>
</select>
<script>
var two = document.getElementById('two');
city = [];//申明

//定义二级数据
city[0] = ['成都市','绵阳市','宜宾市','眉山市','乐山市'];
city[1] = ['太原市','大同市','忻州市','晋中市','长治市'];
city[2] = ['西安市','铜川市','宝鸡市','咸阳市','渭南市'];
function func(m){
two.length = 1;

//遍历生产option选项
for (var i = 0; i < city[m].length; i++) {

//创建一个option 把数据存储在option
var op = new Option(city[m][i],i);

//把带有数据的option 添加到第二个select
two.add(op);
}
}
</script>
</td>
<td><input type="text" placeholder="请输入具体地址" name="address"></td>
</tr>
<tr>
<td>上传头像:</td>
<td><input type="file"></td>
<td></td>
</tr>
<tr>
<td>个人简介:</td>
<td><textarea name="info" cols="30" rows="10"></textarea></td>
<td></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="注册" disabled id="sub" onclick="success()"> <input type="reset" onclick="re()"></td>
<td></td>
</tr>
</table>
</form>
</div>
</body>
</html>