<style>
#app{
width: 187px;
height: 32px;
margin: 50px auto 0;
border: #DDD 1px solid;
display: flex;
}
#app>div{
flex: 1;
display: flex;
justify-content: center;
align-items: center;
}
#app>div:not(:first-of-type){
border-left: #DDD 1px solid;
}
</style>
<body id="body">
<div id="app">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<span id="pass"></span>
<script>
function getById(name){
return document.getElementById(name);
}
var body = getById("body");
var pass = getById("pass");
var p = getById("app").children[0];
var ps = [];
var i = 0;
body.onkeydown = function(){
var code = event.keyCode;
if(8 !=code && (code<48 || code>57)){
return false;
}
if(code==8){
var size = p.innerText.length;
var prev = p.previousElementSibling;
if(size==0){
if(null==prev){
return;
}
p = prev;
i--;
}
p.innerText = "";
ps[i]="";
pass.innerText = ps.join("");
prev = p.previousElementSibling;
if(null!=prev){
p = prev;
i--;
}
}else{
if(p.innerText.length>0){
p = p.nextElementSibling;
i++;
}
p.innerText = code-48;
ps[i] = code-48;
pass.innerText = ps.join("");
var t = p;
setTimeout(function(){
t.innerText = "●";
},200);
if(null==p.nextElementSibling){
window.location="http://www.baidu.com";
return;
}
p = p.nextElementSibling;
i++;
}
}
</script>
</body>