jQuery六位密码输入框

jQuery简单实现六位密码输入框这个小玩意,简单到不想赘述,上代码吧还是。

在这里插入图片描述效果图

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#box{width:480px;height:62px;margin:200px auto 80px;text-align: center;}
		    #box input{
		    	width:60px;
		    	height:60px;
		    	line-height: 60px;
		    	display: inline-block;
		    	border:1px solid #e3e3e3;
		    	background-color: #f5f5f5;
		    	text-align: center;
		    	font-size: 24px;
		    	font-weight: bold;
		    }
		    button{
		    	display: block;
		    	padding:7px 25px;
		    	margin:auto;
		    	border:1px solid #f43b51;
		    	background-color: #F43B51;
		    	color: white;
		    	font-size: 18px;
		    	border-radius: 10px;
		    	cursor: pointer;
		    }
		    button:hover{opacity: 0.7;}
		</style>
	</head>
	<body>
		<div id="box">
			<input type="text" name="password" value="" maxlength="1"/>
			<input type="text" name="password" value="" maxlength="1" disabled="disabled"/>
			<input type="text" name="password" value="" maxlength="1" disabled="disabled"/>
			<input type="text" name="password" value="" maxlength="1" disabled="disabled"/>
			<input type="text" name="password" value="" maxlength="1" disabled="disabled"/>
			<input type="text" name="password" value="" maxlength="1" disabled="disabled"/>
		</div>
		<button id="reset" type="reset">重置</button>
		<script src="js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var passwordStr = '';
			$(document).ready(function(){
				$("#box input").eq(0).focus();
				$("#box input").keyup(function(){
					if(!parseInt($(this).val())){
						$(this).val('');
						return false;
					}
					if(parseInt($(this).index())+1<=$("#box input").length){
						passwordStr += $(this).val();
						console.log(passwordStr);
						$(this).blur();
						$(this).val('❤');
						$(this).attr('disabled','true');
						if(parseInt($(this).index())+1<=$("#box input").length){
							$(this).next('input').removeAttr('disabled');
							$(this).next('input').focus();
						}
					}
				});
				$("#reset").click(function(){
					$("#box input").val('');
					$("#box input").attr('disabled','disabled');
					$("#box input").eq(0).removeAttr('disabled');
					$("#box input").eq(0).focus();
					passwordStr = '';
				});
			});
		</script>
	</body>
</html>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值