密码输入要求

这篇博客主要介绍了使用HTML、CSS和JavaScript实现一个简单的前端密码输入验证。通过设置输入框样式和提示信息,当用户输入的密码长度不符合6~16字符的要求时,会显示错误提示;反之则显示正确提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style>
			*{
				padding: 0px;
				margin: 0px auto;
			}
			
			.box{
				width: 400px;
				height: 120px;
			}
			
			.ipt{
				position:fixed;
				width: 200px;
				height: 50px;
				position: fixed;
				border-radius: 5px;
				margin: 50px 100px;
				color: black;
				font-size: 18px;
				text-align: center;
				
			}
			
			.dian{
				height: 25px;
				width: 180px;
				text-align: center;
				background-color: aqua;
				border-radius: 20px;
				position: fixed;
				margin: 15px 110px;
			}
			
			.wrong{
				background-color: red;
			}
			
			.correct{
				background-color: greenyellow;
			}
		</style>
	</head>
	<body>
		
		
		<div class="box">
			<input type="password" value="输入" class="ipt"/>
			<p class="dian">请输入6~16字符的密码</p></div>
			<script>
				var ipt = document.querySelector('.ipt');
				var btn = document.querySelector('.dian');
				
				ipt.onblur = function(){
					if(this.value.length<6 || this.value.length>16){
						console.log('错误');
						btn.className = 'dian wrong';
					}else{
						console.log('正确');
						btn.className ='dian correct';
					}
				}
			</script>
		</div>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值