花店在线商城html
时间: 2023-12-15 14:32:14 浏览: 77
以下是一个简单的花店在线商城的HTML页面示例,包括商品展示、购物车和结算等功能:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>花店在线商城</title>
<style>
/* 样式表 */
/* 商品展示区域 */
.item {
display: inline-block;
margin: 10px;
padding: 10px;
border: 1px solid #ccc;
width: 200px;
height: 300px;
text-align: center;
}
.item img {
max-width: 100%;
max-height: 200px;
margin-bottom: 10px;
}
.item h3 {
font-size: 18px;
margin-bottom: 10px;
}
.item p {
font-size: 14px;
color: #999;
margin-bottom: 10px;
}
.item button {
background-color: #f90;
color: #fff;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
}
.item button:hover {
background-color: #f60;
}
/* 购物车区域 */
.cart {
position: fixed;
top: 0;
right: 0;
padding: 10px;
background-color: #f90;
color: #fff;
border-radius: 5px 0 0 5px;
cursor: pointer;
}
.cart:hover {
background-color: #f60;
}
/* 结算区域 */
.checkout {
position: fixed;
bottom: 0;
right: 0;
padding: 10px;
background-color: #f90;
color: #fff;
border-radius: 0 5px 5px 0;
cursor: pointer;
}
.checkout:hover {
background-color: #f60;
}
</style>
</head>
<body>
<!-- 商品展示区域 -->
<div class="item">
<img src="flower1.jpg" alt="鲜花1">
<h3>玫瑰花</h3>
<p>价格:99元</p>
<button onclick="addToCart('鲜花1', 99)">加入购物车</button>
</div>
<div class="item">
<img src="flower2.jpg" alt="鲜花2">
<h3>康乃馨</h3>
<p>价格:88元</p>
<button onclick="addToCart('鲜花2', 88)">加入购物车</button>
</div>
<div class="item">
<img src="flower3.jpg" alt="鲜花3">
<h3>百合花</h3>
<p>价格:66元</p>
<button onclick="addToCart('鲜花3', 66)">加入购物车</button>
</div>
<!-- 购物车区域 -->
<div class="cart" onclick="showCart()">购物车</div>
<!-- 结算区域 -->
<div class="checkout" onclick="checkout()">结算</div>
<!-- JavaScript代码 -->
<script>
// 购物车数据
var cartData = {};
// 添加商品到购物车
function addToCart(name, price) {
if (cartData[name]) {
cartData[name].count++;
} else {
cartData[name] = {
price: price,
count: 1
};
}
alert('已添加到购物车');
}
// 显示购物车
function showCart() {
var cartList = '';
var totalPrice = 0;
for (var name in cartData) {
var item = cartData[name];
cartList += name + ' x ' + item.count + ':' + item.price * item.count + '元\n';
totalPrice += item.price * item.count;
}
if (cartList) {
cartList += '总价:' + totalPrice + '元';
} else {
cartList = '购物车为空';
}
alert(cartList);
}
// 结算
function checkout() {
var totalPrice = 0;
for (var name in cartData) {
var item = cartData[name];
totalPrice += item.price * item.count;
}
if (totalPrice > 0) {
alert('总价:' + totalPrice + '元,结算成功');
cartData = {};
} else {
alert('购物车为空');
}
}
</script>
</body>
</html>
```
阅读全文