在Html页面上实现密码可见不可见,使用的阿里巴巴矢量图标库。
html部分:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>网页制作</title> <link rel="stylesheet" type="text/css" href="style.css"> <script src="js/jquery-1.9.1.min.js"></script> <script src="js/home.js"></script> </head> <body style="background-color:#fff;"> <div class="password-wrap"> <div class="password-input"> <input type="password" name="key" value='123456' class="bui-input" autocomplete="off" /> </div> <i class="bt-showpwd off"></i> </div> </body> </html>
Css部分:
@font-face { font-family: 'iconfont'; /* project id 674189 */ src: url('iconfont/font_674189_dvawifegwrj.eot'); src: url('iconfont/font_674189_dvawifegwrj.eot?#iefix') format('embedded-opentype'), url('iconfont/font_674189_dvawifegwrj.woff') format('woff'), url('iconfont/font_674189_dvawifegwrj.ttf') format('truetype'), url('iconfont/font_674189_dvawifegwrj.svg#iconfont') format('svg'); } input::-ms-clear {display:none;} input::-ms-reveal {display:none;} .iconfont { display: inline-block; font-family: 'iconfont'; font-style: normal; text-rendering: auto; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-transform: translate(0, 0); -ms-transform: translate(0, 0); transform: translate(0, 0); -webkit-text-stroke-width: 0.2px; } .bui-input { box-sizing: border-box; height: 40px; padding: 8px 10px; line-height: 24px; border: 1px solid #DDDDDD; color: #5F5F5F; font-size: 14px; vertical-align: middle; border-radius: 4px; width: 330px; } .bui-input:hover{ border: 1px #659aea solid; } .bui-input:focus { outline: none; border: 1px solid #4F9FE9; box-shadow: 0 0 3px 0 #2171BB; color: #595959; } .password-wrap { position: relative; width: 330px; } .password-wrap .bt-showpwd { color: #999999; position: absolute; top: 8px; right: 10px; line-height: 24px; width: 24px; height: 24px; text-align: center; cursor: pointer; } .password-wrap .bt-showpwd.off::before { content: "e60a"; font-family: "iconfont"; font-size: 18px; } .password-wrap .bt-showpwd.on::before { content: "e60b"; font-family: "iconfont"; font-size: 18px; }
效果如下: