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>
.register {
width: 400px;
margin: 100px auto;
}
.pass {
position: relative;
display: inline-block;
width: 200px;
border: 1px solid #ccc;
}
.pass input {
width: 170px;
border: 0px;
outline: none;
}
.pass img {
position: absolute;
top: 2px;
right: 2px;
width: 15px;
margin: 3px 2px 0px;
}
.hint {
display: inline-block;
}
.hint span {
color: red;
vertical-align: middle;
}
.hint .message {
display: inline;
font-size: 12px;
color: #333;
}
style>
head>
<body>
<div class="register">
<div class="pass">
<label>
<img src="img/no_eye.png" alt="" id="eye">
label>
<input type="password" id="pass" maxlength="15">
div>
<div class="hint">
<span>*span>
<p class="message">请输入6~12位密码p>
div>
div>
<script>
var eye = document.querySelector('#eye');
var pass = document.querySelector('#pass');
var span = document.querySelector('span');
var message = document.querySelector('.message');
var flag = 0;
eye.addEventListener('click', function () {
if (flag == 0) {
pass.type = 'text';
eye.src = 'img/eye.png';
flag = 1;
} else {
pass.type = 'password';
eye.src = 'img/no_eye.png';
flag = 0;
}
})
pass.addEventListener('blur', function () {
if (this.value.length < 6 || this.value.length > 12) {
span.innerHTML = '';
message.innerHTML = '输入有误,请输入6~12位密码!'
message.style.color = 'red';
} else {
span.innerHTML = '√';
span.style.color = 'green';
message.innerHTML = '';
}
})
script>
body>
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