怎样用HTML加JS写一个密码输入框(6位密码,密码输入正确自动跳转,错误给出提示)

画面比较简陋

body里面的代码

<span style="font-family: 黑体;">请输入密码:</span><input id="password" type="password" name="密码输入框"/>
		<table width="300" height="300" style="text-align: center;">
			<tr>
				<td id="1" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">1</td>
				<td id="2" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">2</td>
				<td id="3" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">3</td>
			</tr>
			<tr>
				<td id="4" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">4</td>
				<td id="5" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">5</td>
				<td id="6" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">6</td>
			</tr>
			<tr>
				<td id="7" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">7</td>
				<td id="8" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">8</td>
				<td id="9" onmouseenter="doenter(this)" onmouseout="doout(this)" onmousedown="dodown(this)" onmouseup="doup(this)">9</td>
			</tr>
		</table>

js代码

var password = 123456;
var input = document.getElementById("password");
var td = document.getElementsByTagName("td");
for(var i = 0;i < td.length;i++){
	td[i].style.color = "white"
	td[i].style.backgroundColor = "#EAEAEA";
	td[i].style.borderRadius = "50px";
}
function dodown(obj){
	obj.style.backgroundColor = "darkgray";
	input.value += obj.id;
	
}
function doup(obj){
	obj.style.backgroundColor = "#EAEAEA";
	if(input.value.length == 6){
		if(input.value == password){
			alert("登录成功");
			location.href="https://i.baidu.com";
		}else{
			alert("密码错误,登录失败")
			input.value = null;
		}
	}
}
function doenter(obj){
	obj.style.backgroundColor = "lightgray";
}
function doout(obj){
	obj.style.backgroundColor = "#EAEAEA";
}

效果图

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值