2017-10-12 95 views
0

enter image description herejQuery的获取特定ID

我做了这个为我校的项目,但我的问题是现在:

我添加新的汽车我的购物车,当我选择不同的车第一个也会发生变化。所有选定的汽车有自己的价格,但是当我选择不同的车所有的价格都是一样的:

我的代码:

  $('.productprijzen').hide(); 
      var $select = $('<select>').addClass('keuzes'); 

      $select.append('<option>Kies je optie</option>'); 
      $select.append('<option value="volvo">Volvo</option>'); 
      $select.append('<option value="saab">saab</option>'); 
      $select.append('<option value="peugeot">peugeot</option>'); 
      $select.append('<option value="mazda">mazda</option>'); 

      $select.on('change', function() 
      { 
       console.log(); 
       $parent = $(this).closest(".row"); 
       $('.productprijzen',$parent).slideDown(); 


       var merk = $(this).val(); 
       var productInfo = oProducten[merk]; 
       $('.prijs').html("€" + productInfo.prijs); 
       $('.btw').html(productInfo.btw+ "%"); 
       //$('.aantal').html(productInfo.btw+ "%"); 

       // berekening van aantal x prijs 
       var $aantalKeuze = $('input.aantal'); 
       var $subtotaal = $('.qty'); 
       $aantalKeuze.change(function() { 
        $subtotaal.html((productInfo.prijs * $aantalKeuze.val())); 
       }); 
      }); 

      $product = $(".producttemplate"); 
      $('.productkeuzes',$product).append($select.clone(true)); 

      var $i = 1; 
      $(".nieuw").click(function() { 

       $('.producten').append($product.clone(true).addClass('single product'+$i).removeClass('producttemplate')); 
       $i++; 
      }); 
     }); 
+0

你能提供html吗? – madalinivascu

回答

0

您需要添加的价格,顺便说一句,分类汇总当前元素只有

$parent.find('.prijs').html("€" + productInfo.prijs); 
$parent.find('.btw').html(productInfo.btw+ "%"); 
.... 
$subtotaal = $parent.find('.qty'); 
+0

不仅$小额,PRICE和BTW需要是唯一的。当我添加新车时,第一个需要保持自己的价值,第二个需要得到他自己的价值(价格和btw) – Dimitri

+0

@Dimitri是的,正如你可以在我的回答中看到 – madalinivascu

+1

非常感谢你 – Dimitri