登录页面示例

点击明文和密码切换显示。

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}

.box1 {
width: 600px;
height: 400px;
margin: 100px auto;
text-align: center;
}

.myform {
margin: 60px, auto;
padding-top: 30px;
position: relative;
}

.myform input {
width: 500px;
height: 36px;
margin-bottom: 12px;
font-size: 18px;
outline: none;
border: none;
border-bottom: 1px solid rgb(255, 228, 228);
padding-left: 8px;
}

.myform #sub {
height: 48px;
margin-top: 18px;
margin-left: 72px;
outline: none;
border: 1px solid skyblue;
background-color: #FF3C00;
color: #eee;
border-radius: 24px;
}

.myform label {
padding: 0 12px;
color: skyblue;
margin-bottom: 12px;
font-size: 18px;
}

.myform img {
width: 24px;
height: 24px;
position: absolute;
right: 24px;
}

::-webkit-input-placeholder {
/* WebKit browsers */
color: rgba(0, 0, 0, .2);
font-size: 14px;
}
</style>
</head>

<body>
<div class="box1">
<h1 class="title">登录</h1>
<form action="" class="myform">
<label for="username">用户名</label><input type="text" id="username" placeholder="账号">
<label for="pwd">&nbsp;&nbsp;&nbsp;</label><input type="password" id="pwd" placeholder="密码">
<img src="eye-close.png" alt="" id="eye">
<input type="submit" value="登录" id="sub">
</form>
</div>

<script>
var eye = document.getElementById('eye');
var pwd = document.getElementById('pwd');
eye.onclick = function() {
console.log(pwd.type);
if (pwd.type == 'password') {
eye.src = ('eye.png');
pwd.type = 'text';
} else {
pwd.type = 'password';
eye.src = ('eye-close.png');
}
}
</script>

</body>

</html>