Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中添加到购物车_Javascript_Jquery_Html - Fatal编程技术网

在Javascript中添加到购物车

在Javascript中添加到购物车,javascript,jquery,html,Javascript,Jquery,Html,在我的modals中添加了信息之后,我尝试插入一个数量选择器,让客户在我的网站上选择产品的数量,然后管理购物车。可以解释一下我应该如何在Javascript中继续这样做吗 约翰·西蒙斯 HTML 您可以在modal上添加一个下拉列表,允许访问者从列表中选择数量。我这样做了,我使用了数字输入,但我如何使用它在我的购物车中传输它@你现在是怎么做的?“produit.push()”函数调用在做什么?它太难了,用产品信息填充我的数组,然后我用var quantityProduct=document.ge

在我的modals中添加了信息之后,我尝试插入一个数量选择器,让客户在我的网站上选择产品的数量,然后管理购物车。可以解释一下我应该如何在Javascript中继续这样做吗

约翰·西蒙斯

HTML


您可以在modal上添加一个下拉列表,允许访问者从列表中选择数量。我这样做了,我使用了数字输入,但我如何使用它在我的购物车中传输它@你现在是怎么做的?“produit.push()”函数调用在做什么?它太难了,用产品信息填充我的数组,然后我用var quantityProduct=document.getElementByID(“quantity”).value执行了一个名为Add to cart的函数;(数量id已添加到我的html中)@TejSoft
<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">&times;</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>
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;