2 fenglinstudio fenglinstudio 于 2016.04.12 11:13 提问

需要修改这串脚本,目前页面是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";
    }
}

2个回答

showbo
showbo   Ds   Rxr 2016.04.12 12:03
已采纳

更正下,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";
        }
    }
showbo
showbo   Ds   Rxr 2016.04.12 12:02
 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";
        }
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!