表单验证通过输入框获取用户输入的密码,如果输入密码为“happy123”,则显示“密码输入正确”,否则提示“密码输入错误”,如果输入三次,显示提示信息“三分钟后在尝试”

功能:简单的表单验证,密码输入次数控制,定时器控制可输入提醒,密码匹配

Html:请忽略界面设计,没时间做

<form>
    <input id="userName" type="text" placeholder="请输入用户名" onblur="checkUserName()"/><br />
    <input id="userPassword" type="password" placeholder="请输入密码" onclick="inputPassWord()" onblur="checkPassWord()"/><br />
    <input id="verificationCode"  style="width:80px" type="text" placeholder="请输入验证码" />
    <img style="width: 70px;height: 20px;" src="../../img/verificationCode.jpg"/>
</form>
<button style="margin:20px;background: pink;" onclick="checkCode()">登录</button>

js:

var userName = document.getElementById("userName");
var userPassword = document.getElementById("userPassword");
var verificationCode = document.getElementById("verificationCode");
var inputTimes = 0;       //密码输入次数
var canInput = true;    //密码框是否可以输入
//登录按钮点击事件
function checkCode(){
	if(userName.value == ""){
		alert("请输入用户名!");
	}else{
		if (userPassword.value == "happy123"&&verificationCode.value=="7364") {
			alert("登录成功!");
		}
		if (userPassword.value != "happy123") {
			alert("密码错误!");
				verificationCode.value = "";
		}
		if(verificationCode.value!="7364"){
			alert("验证码错误!");
		}	
			
	}
}	
//密码输入离开
function checkPassWord(){
	inputTimes = inputTimes + 1;
}
//密码输入点击事件
function inputPassWord(){
	if (inputTimes>2) {
		alert("请三分钟后在尝试!");
		//定时器3分钟,inputTimes = 0;
		setTimeout(function(){
			inputTimes = 0;
		},180000);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值