我想制作一个基本的购物车应用,您可以在其中点击项目,每次点击都应该将项目添加到数组中。最后,你应该可以按一个总按钮查看你添加的所有项目,但到目前为止它还没有工作。
到目前为止代码:
UPDATE
Location L1
INNER JOIN ConsumerLocation c on c.LocationID=L1.LocationID -- miseed on
SET
L1.StreetNumber = 124,
L1.StreetName = 'Braelands Crescent',
L1.Suburb = 'Albion' ,
L1.City = 'Melbourne',
L1.Postalcode = 9999
WHERE c.UserName = 'Magika'
Jsfiddle:https://jsfiddle.net/xpb8oarx/
答案 0 :(得分:2)
addEventListener
add()
你不需要那样
var shoppingCart = [];
document.getElementById("itemOne").addEventListener("click", function() {
shoppingCart.push("One");
});
document.getElementById("itemTwo").addEventListener("click", function() {
shoppingCart.push("Two");
});
document.getElementById("total").addEventListener("click", function() {
document.getElementById("display").innerHTML = shoppingCart;
});

.container {
width: 70%;
background-color: black;
height: 300px;
margin: 0 auto;
}
#itemOne,
#itemTwo {
width: 100px;
height: 100px;
border: 1px solid white;
margin: 1%;
color: white;
}
#display {
color: white;
text-align: center;
}

<div class="container">
<div id="itemOne" class="itemOne">
<button class=" item">Chicken</button>
</div>
<div id="itemTwo">
<button class="item">Veggies</button>
</div>
<button id="total">Total</button>
<h1 id="display"></h1>
</div>
&#13;
答案 1 :(得分:0)
您将找到一个教程HERE,它解释了如何在纯HTML5和Vanilla中实现购物车。 Tuto由法国JS忍者写的