-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_valiWithCSS_onsubmit.html
70 lines (70 loc) · 1.44 KB
/
4_valiWithCSS_onsubmit.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>实现带样式的表单验证</title>
<link rel="Stylesheet" href="css/4.css" />
<style>
a{
padding:10px 12px;
border:1px solid #555;
border-radius:6px;
text-decoration:none;
color:#555;
display:inline-block;
}
</style>
</head>
<body>
<a href="#top">回到顶部</a>
<form id="form1">
<h2>增加管理员</h2>
<table>
<tr>
<td>姓名:</td>
<td>
<input name="username"/>
<span>*</span>
</td>
<td>
<div class="vali_info">
10个字符以内的字母、数字或下划线的组合
</div>
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type="password" name="pwd"/>
<span>*</span>
</td>
<td>
<div class="vali_info">6位数字</div>
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<input type="submit" value="保存"/>
<input type="reset" value="重填"/>
</td>
</tr>
</table>
</form>
<script src="js/4.js"></script>
<script>
var a=document.getElementsByTagName("a")[0]
a.onclick=function(e){
e.preventDefault()
}
var form=document.forms[0]
form.onsubmit=function(e){
var rName=vali(txtName,/^\w{1,10}$/)
var rPwd=vali(txtPwd,/^\d{6}$/)
if(!(rName&&rPwd)){
e.preventDefault();
}
}
</script>
</body>
</html>