Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Just trying to get a very simple js login to validate a static username/password however cant seem to get it to work. Any help would be appreciated.

var checkLoginPass = function () {
    var login = document.getElementById("login").value;
    var pass = document.getElementById("password").value;
    if (login === "user123" && pass === "password1234") {
        window.location("http://www.google.com");
    }
    else {
        //do something else;
    }
};
<input type="text" id="login" required>
<input type="text" id="password" required>
<input type="button" id="goButton" onclick="checkLoginPass()" value="Log In"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
466 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use location.replace("http://www.google.com"); instead of window.location("http://www.google.com");


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...