js購物車加減按鈕 jquery購物車加減
Netshoes鞋履達(dá)人賣家服務(wù)2025-06-033750
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>購物車</title>
<style>
.cart {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
background-color: #f5f5f5;
border-radius: 5px;
}
.cart button {
margin-right: 10px;
padding: 5px 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.cart button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="cart">
<button onclick="addToCart('item1')">加入購物車</button>
<button onclick="addToCart('item2')">加入購物車</button>
<button onclick="addToCart('item3')">加入購物車</button>
</div>
<script>
function addToCart(product) {
// 在這里添加將產(chǎn)品添加到購物車的代碼
console.log('商品:' + product + ' 已添加到購物車');
}
</script>
</body>
</html>
這是一個(gè)簡(jiǎn)單的購物車頁面,包含三個(gè)按鈕分別代表三個(gè)商品。點(diǎn)擊每個(gè)按鈕時(shí),會(huì)調(diào)用addToCart
函數(shù),將商品信息添加到購物車中。你可以根據(jù)實(shí)際需求修改這個(gè)示例。
大家都在看:
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。