写一个购物车的前端页面
时间: 2024-02-16 21:03:29 浏览: 68
以下是一个简单的购物车前端页面示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>购物车</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 10px;
text-align: center;
border: 1px solid #ccc;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.fa {
color: #bfbfbf;
cursor: pointer;
margin-right: 10px;
}
.fa:hover {
color: #ff6666;
}
.total {
text-align: right;
margin-bottom: 20px;
}
.total span {
font-weight: bold;
font-size: 20px;
}
.btn {
background-color: #ff6666;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>购物车</h1>
<table>
<thead>
<tr>
<th>商品名称</th>
<th>单价</th>
<th>数量</th>
<th>小计</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>IPhone 12</td>
<td>¥7999.00</td>
<td>1</td>
<td>¥7999.00</td>
<td><i class="fa fa-trash"></i></td>
</tr>
<tr>
<td>Oppo Find X3</td>
<td>¥5999.00</td>
<td>2</td>
<td>¥11998.00</td>
<td><i class="fa fa-trash"></i></td>
</tr>
</tbody>
</table>
<div class="total">
<span>总计:¥19997.00</span>
</div>
<button class="btn">结算</button>
</div>
<script>
// 绑定删除按钮的点击事件
const deleteBtns = document.querySelectorAll('.fa-trash');
deleteBtns.forEach(btn => {
btn.addEventListener('click', () => {
btn.parentElement.parentElement.remove();
});
});
</script>
</body>
</html>
```
该页面包括商品列表、总计金额和结算按钮。每行商品信息包括商品名称、单价、数量、小计和删除按钮。删除按钮绑定了点击事件,点击后可以删除对应的商品行。
阅读全文