在我的模态中添加信息后,我试图插入数量选择器以获得客户在我的网站上选择的产品数量,然后管理购物车。可以解释一下我该如何在Javascript中继续这样做?
John Simmons
HTML
<button type="button" id="bouton" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" onclick="showProduct(1);">Add to cart</button>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><span id="product_nom"></span></h4>
</div>
<div class="modal-body">
<div class="row">
<span><b>Product tag : </b></span><span id="product_tag"></span>
</div>
<div class="row">
<span><b>Product price : </b></span>
<span id="product_price"></span>
</div>
<div class="row">
<span><b>Product image : </b></span>
<img id="product_image" src=""/>
</div>
<div class="row">
<span><b>Product description : </b></span>
<span id="product_description"></span>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
Javascript
function produits(tag, nom, price, imagesrc, description){
this.Tag = tag;
this.Nom = nom;
this.Price = price;
this.SRC = imagesrc;
this.Description = description;
}
var produit = [];
//6x for my 6 products
produit.push(new produits(1, "nom", 35, "path/to/img","Description"));
function showProduct(productId){
document.getElementById("product_tag").innerHTML = produit[productId-1].Tag;
document.getElementById("product_nom").innerHTML = produit[productId-1].Nom;
document.getElementById("product_price").innerHTML = produit[productId-1].Price;
document.getElementById("product_image").src = produit[productId-1].SRC;
document.getElementById("product_description").innerHTML = produit[productId-1].Description;