下面是我编写的一个快速函数,用于检查提供的输入是否等于某个预定义的值。如果是,则应显示“登录成功”。
function getUsername(){
var username = document.getElementById("userID").nodeValue;
var password = document.getElementById("password").nodeValue;
if (username=="example@example.com" && password=="123"){
alert('Login Successful');
}
}
<input class="input100" type="text" name="username" placeholder="Username"
id="userID">
<input class="input100" type="password" name="pass" placeholder="Password"
id="password">
<Button class="login100-form-btn" onclick="getUsername()">Login</Button>
答案 0 :(得分:1)
您应该使用.value
获取input
元素的值:
function getUsername() {
var username = document.getElementById("userID").value;
var password = document.getElementById("password").value;
if (username == "example@example.com" && password == "123") {
alert('Login Successful');
}
}
<input class="input100" type="text" name="username" placeholder="Username" id="userID">
<input class="input100" type="password" name="pass" placeholder="Password" id="password">
<Button class="login100-form-btn" onclick="getUsername()">Login</Button>