js教程

简单的JS判断用户登录代码

精准像素 2021-10-22 人阅读
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var userList = [
            {
                name: '张三',
                pwd: '123456'
            },
            {
                name: '李四',
                pwd: '654321'
            }
        ]
        function errorpwd() {
            var np = prompt('请重新输入密码');
            if (np === cp) {
                alert('登陆成功');
                flag = 1;
            } else {
                errorpwd();
            }
        }
        while (true) {
            var n = prompt('请输入账号');
            for (var i = 0; i < userList.length; i++) {
                if (n === userList[i].name) {
                    var num = i;
                    var p = prompt('请输入密码');
                    if (p === userList[num].pwd) {
                        alert('登陆成功');
                        var flag = 1;
                        break;
                    } else {
                        alert('密码错误');
                        cp = userList[num].pwd;
                        errorpwd();
                        break;
                    }
                }
            }
            if (flag === 1) {
                break;
            }
        }
    </script>
</head>
<body>
</body>
</html>


相关推荐
  • JS判断
  • 简单的JS判断用户登录代码

    <!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scal...

    js教程 20 6个月前
  • JS判断IE浏览器版本

    简单的原生JS判断IE浏览器版本var DEFAULT_VERSION = 8.0; var ua = navigator.userAgent.toLowerCase(); var isIE = ua.indexOf("msie")>-1; var safariVersion; if(isIE){ safariVersion = ua.match(/msie ([\d.]+)/)[1]; } if(safariVe...

    js教程 109 2年前
  • JS判断input file图片宽度完美兼容版

    判断input file图片宽度、大小最好的方法是用后端提交后来判断,但对应不会程序的朋友怎么办,门槛有点高。之前有分享过一次利用JS来判断input file图片宽度教程,但有个BUG,当第一次触发change方法判断true时,第二次input file随意选择一个都不会再次触发...

    js教程 122 2年前