问题描述
- 下面的脚本我想实现连续输入3次账号密码错误自动跳转到禁止登陆页面怎么实现
-
<script> function check(){ var name=document.getElementById("name").value; var pass=document.getElementById("pass").value; if(name=="账号" && pass=="密码"){ alert("登入成功"); window.document.f.action="shujubiao/"; window.document.f.submit(); }else{ alert("用户名或密码错误"); } } </script>
解决方案
var errCount = 0;
function check() {
if (errCount < 3) {
var name = document.getElementById("name").value;
var pass = document.getElementById("pass").value;
if (name == "账号" && pass == "密码") {
errCount = 0;
alert("登入成功");
window.document.f.action = "shujubiao/";
window.document.f.submit();
} else {
errCount++;
alert("用户名或密码连续错误次数" + errCount);
}
}
if (errCount == 3) {// 连续输入3次账号密码错误
location.href = "登陆页地址..";
}
}
解决方案二:
function check() {
var name = document.getElementById("name").value;
var pass = document.getElementById("pass").value;
if (name == "账号" && pass == "密码") {
alert("登入成功");
window.document.f.action = "shujubiao/";
window.document.f.submit();
} else {
alert("用户名或密码错误");
count++;
if (count >= 3) location = 'xxxxxx';
}
}
时间: 2025-01-26 13:59:15