js登陆页面输入正确的账号密码后跳转页面
时间: 2023-11-11 16:04:19 浏览: 66
当用户在登录页面输入正确的账号密码后,可以通过 JavaScript 来实现页面跳转。以下是一个简单的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<form id="login-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<input type="button" value="Login" onclick="login()">
</form>
<script>
function login() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
// 模拟账号密码验证
if (username === "admin" && password === "123456") {
window.location.href = "home.html"; // 跳转到 home.html 页面
} else {
alert("Invalid username or password!");
}
}
</script>
</body>
</html>
```
在上面的代码中,当用户点击登录按钮时,会调用 `login()` 函数来验证账号密码是否正确。如果验证通过,就会通过 `window.location.href` 来跳转到 `home.html` 页面。如果验证不通过,则会弹出一个提示框提示用户输入的账号密码无效。你可以根据实际需求来修改账号密码验证的逻辑和跳转的目标页面。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)