问题描述
- 需要修改这串脚本,目前页面是login.html,输错三次密码后会跳转到nologin.html页面
-
需要修改这串脚本,目前页面是login.html,输错三次密码后会跳转到nologin.html页面,现在新增一个页面:wait.html。想达到的效果是一旦进入nologin.html,5分钟内进入login.html会自动跳转到wait.html,5分钟后进入login.html可以正常进入。cookie实现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 = "in.html"; window.document.f.submit(); } else { errCount++; alert("用户名或密码连续错误次数" + errCount); } } if (errCount == 3) {// 连续输入3次账号密码错误 location.href = "nologin.html"; } }
解决方案
更正下,setCookie放错位置
function setCookie() {
var d = new Date();
d.setMinutes(d.getMinutes() + 5);
document.cookie = 'visit1=1;expires=' + d.toGMTString();
}
if (document.cookie.indexOf('visit1=1') != -1) location = 'wait.html';/////////////////////
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 = "in.html";
window.document.f.submit();
} else {
errCount++;
alert("用户名或密码连续错误次数" + errCount);
}
}
if (errCount == 3) {// 连续输入3次账号密码错误
setCookie();//////////////////////
location.href = "nologin.html";
}
}
解决方案二:
function setCookie() {
var d = new Date();
d.setMinutes(d.getMinutes() + 5);
document.cookie = 'visit1=1;expires=' + d.toGMTString();
}
if (document.cookie.indexOf('visit1=1') != -1) location = 'wait.html';/////////////////////
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 = "in.html";
window.document.f.submit();
} else {
setCookie();//////////////////////
errCount++;
alert("用户名或密码连续错误次数" + errCount);
}
}
if (errCount == 3) {// 连续输入3次账号密码错误
location.href = "nologin.html";
}
}
时间: 2024-10-28 15:11:28