HTML支付密码输入框(已实现)

密码输入框思路梳理:

        a:用lable包裹li标签和input框;

        b:input设置最大输入值为6;

        c:用input框的输入值分别遍历到6个li标签中;

代码需要引入jQuery代码:http://libs.baidu.com/jquery/2.1.4/jquery.min.js

HTML代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>支付密码输入框</title>
	<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
	<style type="text/css">
		ul,li{
			list-style: none;
		}
		.password-div input{
			width: 1px;
			height: 1px;
			opacity: 0;
			border: 0;
		}
		.password-lable{
			height: 30px;
			clear: both;
		}
		.password-lable li{
			float: left;
			width: 30px;
			height: 30px;
			line-height: 30px;
			text-align: center;
			border: 1px solid #dedede;
			margin-left: -1px;
		}

	</style>
</head>
<body>
	<div class="password-div">
		<label for="password" class="password-lable">
			<ul>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
			</ul>
			<input id="password" type="password" name="password" maxlength="6">
		</label>
	</div>
</body>
</html>

我将JS代码拿出来,单独写下

<script type="text/javascript">
	$(".password-div input").on("input",function(e){ //标签为password-div下的input添加oninput事件
		var number = 6;   //定义输入最大值
		var pw = $("input[name = 'password']").val(); //定义pw为name是password的input框的输入值
		var list = $(".password-div ul li");  //定义list是li
		for(var i = 0; i < number ; i++){    //for循环遍历将·放入li标签
			if(pw[i]){
				$(list[i]).text("·");
			}else{
				$(list[i]).text("");
			};
		};
	});
	$(".password-div ul").click(function(){      
		$("input[name = 'password']").val("");
		$("#password").focus();
		$(".password-div ul li").text("");
	});
</script>

 

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值