0
我目前正在某人的網站上工作,併爲每個產品創建了6種不同的模式。但是當我點擊模式按鈕時,我想在每個模式中插入他的內容。在我的模態中創建動態內容在JS
到目前爲止,我已經做到了這一點:
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"));
In html I created my modals 6x this way
<button type="button" id="bouton" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">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">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
現在我想補充的是我存放在我的陣列到我的情態動詞我6種產品的內容。有人可以幫我解決這個問題嗎?
非常感謝您提前。
約翰
有什麼的[ProductID-1]? @Lalit –
@JohnSimmons它是您的產品陣列中添加產品的索引或位置。我已將其命名爲productId,您可以將其重命名爲產品索引。就像你想要顯示6個產品的產品信息一樣,你可以在按鈕的點擊事件上傳遞產品索引的值爲1,2,3,4,5和6。 – Lalit
@JohnSimmons我們在您的產品陣列中添加了第一款產品。所以它會被添加到索引0中。現在我們在按鈕的單擊事件中傳遞1作爲產品索引,因此我們從傳遞的索引中減去1,即「1」以獲得產品陣列中此產品的位置,即「 0" 。在給出的例子中,它將是[1-1]。 – Lalit