我无法重定向到另一个页面,它所做的只是显示我在网址中输入的密码和用户。然而,当我使用 window.open(); 时,它确实可以在 YouTube 等链接中工作。我尝试了在 youtube 上看过的各种代码,但我仍然不知道该怎么做
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="login-wrapper">
<form action="" class="form">
<h2> Login </h2><br>
<div class="input-group">
<label for="id">User ID </label>
<input type="text"
name="id"
id="User ID"
placeholder="User ID"
required />
</div>
<div class="input-group">
<label>Password </label>
<input type="password"
name="password"
placeholder="Password"
id="password" required />
</div>
<input type="submit" value="Login" class="submit-btn" onclick= "auth()" style="font-size:18px;" />
</form>
</div>
<script>
function auth(){
var UserID = document.getElementById("UserID").value;
var password = document.getElementById("password").value;
if(UserID== "admin" && password=="admin123"){
window.location.href="teachergui.html";
alert("Login Successfully ");
}
else{
alert("Invalid User");
return;
}
}
</script>
</div>
</body>
</html> Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您正在使用代码调用该值:
var UserID = document.getElementById("UserID").value;但是您输入的 UserID 有一个空格: