用js设计一个个人空间登陆界面
时间: 2024-03-25 16:38:27 浏览: 13
以下是一个简单的个人空间登录界面的示例代码,你可以根据实际需求进行修改和完善:
```html
<!DOCTYPE html>
<html>
<head>
<title>My Space Login</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
h1 {
text-align: center;
margin-top: 50px;
}
form {
margin: 50px auto;
padding: 20px;
background-color: #ffffff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
width: 400px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"], input[type="password"] {
padding: 10px;
border-radius: 5px;
border: none;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
width: 100%;
margin-bottom: 20px;
font-size: 16px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #ffffff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<h1>My Space Login</h1>
<form id="login-form">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="Login">
</form>
<script>
var loginForm = document.getElementById("login-form");
loginForm.addEventListener("submit", function(event) {
event.preventDefault(); // 阻止表单提交
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
// 模拟账号密码验证
if (username === "admin" && password === "123456") {
window.location.href = "my_space.html"; // 跳转到个人空间页面
} else {
alert("Invalid username or password!");
}
});
</script>
</body>
</html>
```
在上面的代码中,当用户点击登录按钮时,会通过 JavaScript 来验证账号密码是否正确,如果验证通过,就会跳转到 `my_space.html` 页面。如果验证不通过,则会弹出一个提示框提示用户输入的账号密码无效。你可以根据实际需求来修改账号密码验证的逻辑和跳转的目标页面,也可以根据自己的喜好来美化界面样式。