????结合HTML+CSS+JS
里面还有很多完整的效果没有实现
<!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>Document</title>
<style>
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?7kkyc2');
src: url('fonts/icomoon.eot?7kkyc2#iefix') format('embedded-opentype'), url('fonts/icomoon.ttf?7kkyc2') format('truetype'), url('fonts/icomoon.woff?7kkyc2') format('woff'), url('fonts/icomoon.svg?7kkyc2#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
button {
font-family: icomoon;
border: none;
background-color: white;
}
a {
text-decoration: none;
color: black
}
div {
width: 800px;
height: 50px;
margin-top: 20px;
}
div h3 {
text-align: center;
}
input {
border: none;
height: 48px;
width: 650px
}
.shu1,
.shu2 {
border-bottom: 1px solid rgb(163, 155, 155);
}
.left {
float: left;
}
.right {
float: right;
}
.dengl {
background-color: rgb(224, 98, 14);
border-radius: 30px;
text-align: center;
line-height: 50px;
color: white;
height: 50px
}
.left a,
.right a {
color: rgb(108, 111, 114)
}
</style>
</head>
<body>
<div>
<h3>京东登录</h3>
</div>
<div class="shu1"> <input type="text" value="用户名/邮箱/已验证手机"></div>
<div class='shu2'><span> <input type="password" class="pa">
</span><button>?</button> |<span> <a href="#">忘记密码</a></span></div>
<div class="dengl">
<a href="">登录</a>
</div>
<div><span class='left'><a href="" >短信验证码登录</a></span> <span class="right"><a href="" >手机快速注册</a></span></div>
<script>
var but = document.querySelector('button')
var pass = document.querySelector('.pa')
but.onclick = function() {
pass.type = 'text';
but.onclick = function() {
pass.type = 'password'
}
}
</script>
</body>
</html>
核心思路:
点击眼睛按钮,把密码框类型改为文本框就可以看见里面的密码
一个按钮两个状态,点击一次,切换为文本,继续点击一次切换为密码框
算法:利用一个flag变量,来判断flag的值,如果是1就切换为文本框,flag设置为0,如果是0就切换为密码框,flag设置为1(密码框:0 ? 文本框:1)
?
?
<!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>Document</title>
<style>
.box {
width: 400px;
margin: 100px auto;
border-bottom: 1px solid #cccc;
position: relative;
}
.box input {
width: 370px;
height: 30px;
border: 0px;
outline: none
}
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?7kkyc2');
src: url('fonts/icomoon.eot?7kkyc2#iefix') format('embedded-opentype'), url('fonts/icomoon.ttf?7kkyc2') format('truetype'), url('fonts/icomoon.woff?7kkyc2') format('woff'), url('fonts/icomoon.svg?7kkyc2#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
button {
font-family: icomoon;
border: none;
width: 24px;
background-color: white;
position: absolute;
top: 15px;
right: 2px
}
</style>
</head>
<body>
<div class="box"><label for=""><button>?</button></label><input type="password"></div>
<script>
//获取元素
var btn = document.querySelector('button')
var pss = document.querySelector('input')
//注册事件 处理程序
var flag = 0
btn.onclick = function() {
if (flag == 0) {
pss.type = 'text'
btn.innerHTML = '?'
flag = 1
} else {
pss.type = 'password'
btn.innerHTML = '?'
flag = 0
}
}
</script>
</body>
</html>
?
|