Javascript密码检查器

时间:2016-06-15 11:43:54

标签: javascript if-statement

我使用javascript和if循环进行密码检查。但是,当我输入不是javascript的字符串时,不会显示任何警报。这是我的代码。

<script type = "text/javascript">
function password_prompt() {

    var password = window.prompt("Please enter the correct password ", ""); //password = javascript
    if (password == "javascript") {
    var x = window.confirm("Please confirm you want to enter the webpage!");
        if (x != 1) {
        window.close();
        window.open("https://www.google.com/");
    }
    if (password != "javascript") {
        window.alert("You entered the wrong password! Page will now close!");
    window.close();
    window.open("about:blank");
        }

    }
}
</script>

2 个答案:

答案 0 :(得分:-1)

&#13;
&#13;
<script type = "text/javascript">
function password_prompt() {

    var password = prompt("Please enter the correct password ", ""); //password = javascript
    if (password == "javascript") {
    var x = confirm("Please confirm you want to enter the webpage!");
        if (x != 1) {
        window.close();
        window.open("https://www.google.com/");
    }
    if (password != "javascript") {
        alert("You entered the wrong password! Page will now close!");
    window.close();
    window.open("about:blank");
        }

    }
}
</script>
&#13;
&#13;
&#13;

答案 1 :(得分:-1)

<script type = "text/javascript">
function password_prompt() {

    var password = window.prompt("Please enter the correct password ", ""); //password = javascript
    if (password == "javascript") {
        var x = window.confirm("Please confirm you want to enter the webpage!");
        if (x != 1) {
            window.close();
            window.open("https://www.google.com/");
        }
    }
    if (password != "javascript") {
        window.alert("You entered the wrong password! Page will now close!");
        window.close();
        window.open("about:blank");
    }
}
</script>
相关问题