密码输入框



 







<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>

<script src="jquery-1.9.1.min.js"></script>

<style>
input{
width:30px;
height:30px;
border: 1px solid black;
text-align: center;
}
</style>
</head>
<body>
<div>
<input type="text">
<input type="text">
<input type="text">
<input type="text">
<input type="text">
<input type="text">
</div>
<script>
inputPw("div")
function inputPw(container){
$(container+" input[type=text]").bind("input",function(){
var val=$(this).val();
var nextVal=$(this).next().val();
if($(this).next().length!=0){
if(nextVal.length==0){
if(val.length==1){
$(this).next().focus()
}
}else{
if(val.length>=2){
$(this).val(val.substring(1))
}
}
}else{
if(val.length>=2){
$(this).val(val.substring(1))
}
}
})
}

</script>
</body>
</html>


















































posted @ 2018-04-02 15:08  刘浩2561179983  阅读(150)  评论(0编辑  收藏  举报