补充一下登录界面的代码
时间: 2023-09-08 14:11:55 浏览: 71
好的,这里给出一个简单的登录界面的代码,包含HTML、CSS和JavaScript部分:
HTML部分:
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Login</h1>
<form>
<label for="username">Username</label>
<input type="text" id="username" name="username">
<label for="password">Password</label>
<input type="password" id="password" name="password">
<button type="submit" id="submit-btn">Submit</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
```
CSS部分:
```
* {
box-sizing: border-box;
}
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
.container {
background-color: #fff;
border-radius: 5px;
margin: 100px auto;
padding: 20px;
text-align: center;
width: 400px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
h1 {
color: #333;
margin-bottom: 20px;
}
form label {
display: block;
font-size: 16px;
font-weight: bold;
margin-bottom: 10px;
text-align: left;
}
form input[type="text"],
form input[type="password"] {
border-radius: 5px;
border: 1px solid #ccc;
font-size: 16px;
padding: 10px;
width: 100%;
margin-bottom: 20px;
}
form button {
background-color: #4CAF50;
border: none;
border-radius: 5px;
color: white;
cursor: pointer;
font-size: 16px;
font-weight: bold;
padding: 10px 20px;
transition: background-color 0.3s;
}
form button:hover {
background-color: #3e8e41;
}
```
JavaScript部分:
```
const form = document.querySelector('form');
const usernameInput = document.querySelector('#username');
const passwordInput = document.querySelector('#password');
const submitBtn = document.querySelector('#submit-btn');
form.addEventListener('submit', (e) => {
e.preventDefault(); // 阻止表单默认提交行为
const username = usernameInput.value;
const password = passwordInput.value;
if (username === 'admin' && password === '123456') {
alert('Login Success!');
// 登录成功后的操作
} else {
alert('Username or Password is incorrect!');
}
});
```
这个登录界面包含了一个表单,用户需要输入用户名和密码才能提交表单。表单提交时,会检查用户名和密码是否正确,如果正确,则提示登录成功,并执行登录成功后的操作,否则提示用户名或密码错误。
阅读全文