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