写一个前端登录界面,登录成功后跳转到一个家庭账本系统的前端界面
时间: 2024-03-16 15:43:56 浏览: 17
好的,我可以为您提供一个简单的前端登录界面,使用HTML、CSS和JavaScript编写,然后在登录成功后使用JavaScript跳转到家庭账本系统的前端界面。
以下是示例代码:
HTML部分:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
<link rel="stylesheet" href="login.css">
</head>
<body>
<div class="login-box">
<h2>登录</h2>
<form>
<div class="user-box">
<input type="text" name="" required="">
<label>用户名</label>
</div>
<div class="user-box">
<input type="password" name="" required="">
<label>密码</label>
</div>
<a href="#" onclick="login()">登录</a>
</form>
</div>
<script src="login.js"></script>
</body>
</html>
```
CSS部分:
```
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
body {
background: #f2f2f2;
}
.login-box {
width: 280px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
background: #333;
padding: 30px;
border-radius: 5px;
}
.login-box h2 {
margin: 0 0 20px;
padding: 0;
color: #fff;
text-align: center;
}
.login-box .user-box {
position: relative;
}
.login-box .user-box input {
width: 100%;
padding: 10px 0;
font-size: 16px;
color: #fff;
margin-bottom: 30px;
border: none;
border-bottom: 1px solid #fff;
outline: none;
background: transparent;
}
.login-box .user-box label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 16px;
color: #fff;
pointer-events: none;
transition: 0.5s;
}
.login-box .user-box input:focus ~ label,
.login-box .user-box input:valid ~ label {
top: -20px;
left: 0;
color: #03a9f4;
font-size: 12px;
}
.login-box a {
display: block;
margin-top: 30px;
padding: 10px 0;
text-align: center;
color: #fff;
border: none;
border-radius: 5px;
outline: none;
background: #03a9f4;
cursor: pointer;
transition: 0.5s;
text-decoration: none;
}
.login-box a:hover {
background: #fff;
color: #333;
}
```
JavaScript部分:
```
function login() {
// 获取用户名和密码输入框的值
var username = document.getElementsByName("")[0].value;
var password = document.getElementsByName("")[1].value;
// 判断用户名和密码是否正确,这里需要根据实际情况修改
if (username === "admin" && password === "123456") {
// 登录成功,跳转到家庭账本系统前端界面
window.location.href = "home.html";
} else {
// 登录失败,弹出提示框
alert("用户名或密码错误!");
}
}
```
在以上代码中,我们使用了HTML、CSS和JavaScript来实现一个简单的登录界面,其中包括输入框和登录按钮。当用户输入正确的用户名和密码后,点击登录按钮就会执行JavaScript代码中的login()函数,根据用户名和密码的正确性进行跳转或提示用户登录失败。