帮我写一个详细的场地预约后台管理模板,用HTML,JS,CSS
时间: 2024-03-24 08:35:41 浏览: 12
好的,以下是一个简单的场地预约后台管理模板,使用HTML、JS、CSS编写:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>场地预约后台管理系统</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<h1>场地预约后台管理系统</h1>
<!-- 预约表单 -->
<form id="reservation-form">
<h2>新建预约</h2>
<label for="name">预约人姓名:</label>
<input type="text" id="name" name="name" required>
<label for="date">预约日期:</label>
<input type="date" id="date" name="date" required>
<label for="time">预约时间:</label>
<input type="time" id="time" name="time" required>
<label for="venue">预约场地:</label>
<select id="venue" name="venue" required>
<option value="">请选择</option>
<option value="1">场地1</option>
<option value="2">场地2</option>
<option value="3">场地3</option>
</select>
<button type="submit">提交</button>
</form>
<!-- 预约列表 -->
<div id="reservation-list">
<h2>预约列表</h2>
<table>
<thead>
<tr>
<th>预约人姓名</th>
<th>预约日期</th>
<th>预约时间</th>
<th>预约场地</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<!-- 预约数据将在JS中动态生成 -->
</tbody>
</table>
</div>
</div>
<script src="main.js"></script>
</body>
</html>
```
CSS代码:
```css
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0px 0px 10px #aaa;
}
h1 {
text-align: center;
}
form {
margin-bottom: 20px;
}
form h2 {
margin-bottom: 10px;
}
form label {
display: block;
margin-bottom: 5px;
}
form input[type="text"],
form input[type="date"],
form input[type="time"],
form select {
display: block;
width: 100%;
padding: 10px;
margin-bottom: 10px;
font-size: 16px;
border-radius: 5px;
border: none;
}
form button[type="submit"] {
background-color: #4CAF50;
color: #FFF;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
form button[type="submit"]:hover {
background-color: #3e8e41;
}
#reservation-list h2 {
margin-top: 20px;
margin-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
}
table th, table td {
padding: 10px;
text-align: left;
}
table th {
background-color: #4CAF50;
color: #FFF;
}
table tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
table tbody tr:hover {
background-color: #ddd;
}
table tbody td:last-child a {
color: #f00;
text-decoration: none;
}
```
JS代码:
```javascript
// 预约数据
var reservations = [];
// 获取预约表单元素
var reservationForm = document.getElementById("reservation-form");
// 获取预约列表元素
var reservationList = document.getElementById("reservation-list");
// 提交预约表单
reservationForm.addEventListener("submit", function(event) {
event.preventDefault();
// 获取预约信息
var name = document.getElementById("name").value;
var date = document.getElementById("date").value;
var time = document.getElementById("time").value;
var venue = document.getElementById("venue").value;
// 添加预约数据
reservations.push({
name: name,
date: date,
time: time,
venue: venue
});
// 清空表单
reservationForm.reset();
// 更新预约列表
updateReservationList();
});
// 删除预约
function deleteReservation(index) {
reservations.splice(index, 1);
updateReservationList();
}
// 更新预约列表
function updateReservationList() {
// 清空预约列表
reservationList.querySelector("tbody").innerHTML = "";
// 添加预约数据到列表
for (var i = 0; i < reservations.length; i++) {
var reservation = reservations[i];
// 创建表格行
var row = document.createElement("tr");
row.innerHTML = "<td>" + reservation.name + "</td><td>" + reservation.date + "</td><td>" + reservation.time + "</td><td>" + reservation.venue + "</td><td><a href='#' onclick='deleteReservation(" + i + ")'>删除</a></td>";
// 添加行到表格
reservationList.querySelector("tbody").appendChild(row);
}
}
// 初始化预约列表
updateReservationList();
```
这是一个简单的模板,可以用作场地预约后台管理系统的基础,您可以根据自己的需求进行修改和扩展。