用JS实现的类似QQ密码的输入特效

时间:2023-03-09 03:49:42
用JS实现的类似QQ密码的输入特效
<input ID="_PSD"></input>
<script>
function passwordText(ID,pd,mark){
mark=mark||"*"
var PSD=document.getElementById(ID)
var password=pd
var lh=PSD.value.length
setInterval(function(){
if(PSD.value.length!=lh){
if(PSD.value.length>lh)run(1)
else run(0)
lh=PSD.value.length
}
},1)
function run(n){
switch(n){
case 0:
password.length-=1
break
case 1:
password.push(PSD.value.charAt(PSD.value.length-1))
break
}
PSD.value=""
for(var i=0;i<password.length-1;i++)
PSD.value+=mark
if(password.length)
PSD.value+=password[password.length-1]
}
}
var password=[]
passwordText("_PSD",password,"*")
</script>