-
Notifications
You must be signed in to change notification settings - Fork 0
/
输入密码判断长度.html
58 lines (57 loc) · 1.68 KB
/
输入密码判断长度.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>输入密码判断长度</title>
<style>
.box{
margin: 100px auto;
/* background-color: royalblue; */
}
.box input{
padding: 5px;
height: 8px;
outline: none;
}
.warn{
display: inline-block;
font-size: 12px;
color: #ccc;
background: url(/img/warn.jpg) no-repeat left center;
background-size: 13px;
padding-left: 15px;
}
.change{
color: red;
display: inline-block;
font-size: 12px;
background: url(/img/wrong.jpg) no-repeat left center;
padding-left: 15px;
background-size: 13px;
}
</style>
</head>
<body>
<div class="box">
<input type="text" name="">
<p class="warn">请输入6~16位的密码</p>
</div>
<script>
var inp = document.querySelector('input');
var text = document.querySelector('.warn');
inp.onblur = function(){
//表单中值的长度inp.value.length
if(this.value.length < 6){
console.log('错误');
text.className = 'warn change';
text.innerHTML = '重新输入大于6位';
}else{
text.className = 'warn';
text.innerHTML = '正确';
}
}
</script>
</body>
</html>