先展示效果:
代码实现:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"> <title></title> <style type="text/css" > *{margin: 0;padding: 0;border: 0;outline: 0;font-size: 100%;vertical-align: baseline;background: transparent;} *{tap-highlight-color:rgba(0,0,0,0); -webkit-tap-highlight-color:rgba(0,0,0,0);} .password{ width: 80%; height:40px; margin: 50px auto; position: relative; text-align: center; overflow: hidden; } .password .password_bg{ position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; } .password .password_bg span{ float: left; margin-right: 3%; width: 14%; height: 100%; line-height: 40px; height: 40px; font-size: 100px; background-color: #f1f1f1; } .password .password_bg span:last-child{margin: 0;} .password input{ position: absolute; left: -100%; top: 0; -webkit-appearance: none; appearance: none; width: 200%; height: 100%; opacity: 0; } p{text-align: center;} </style> </head> <body> <div class="password"> <div class="password_bg" id="showPasswd"> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div> <input type="tel" id="passwd" maxlength="6"> </div> <p>提交</p> </body> </html> <script> var aSpan = QueryAll("#showPasswd span"); Query("#passwd").addEventListener("input",function(){ var len = this.value.length; for (var i = 0; i< aSpan.length; i++){ if(len > 0){ aSpan[i].innerHTML = "·"; len--; }else{ aSpan[i].innerHTML = "";; } }; },false); Query("p").onclick = function (){ alert(Query("#passwd").value ) ; } function Query(e){return document.querySelector(e);} function QueryAll(e){return document.querySelectorAll(e);} </script>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了