2014-12-16 24 views
5

this jsfiddle'u hazırladım. Komutumun, seçilen her bir özellik özellik fiyatının iki katı kadarını hesaplamasını nasıl hazırladım. Lütfen bu sorunu çözmek için bana yardımcı olun.JS betiği miktarını hesaplar yanlış hesaplar

optionsamount yanlıştır, yani iki kere hesaplanır. Neden bu? Teşekkür

function update_amounts(){ 
    var sum = 0.0; 
    var optionsamount = 0.0; 

    $('#basketorder > tbody > .product').each(function() { 

     $('.selectedoptionselect option:selected').each(function(){ 
      optprice = $(this).attr('price'); 
      optionsamount+= parseFloat(optprice);  
     }) 

     var qty = $(this).find('.qty option:selected').val(); 
     var price = $(this).find('.price').val(); 
     var amount = (qty*price); 
     sum+= (amount + optionsamount); 

     $(this).find('.amount').text(''+ amount.toFixed(2)); 
    }); 

    $('.total').text(sum); 
} 
+0

deneyin' – caramba

+0

thats değil nokta I inan :) – Europeuser

+0

Evet, keman oldukça işe yaramaz. – forgivenson

cevap

3

bu deneyin keman içinde

function update_amounts(){ 
var sum = 0.0; 

$('#basketorder > tbody > .product').each(function() { 

    var optionsamount = 0.0; 


    $(this).find('.selectedoptionselect option:selected').each(function(){ 
     optprice = $(this).attr('price'); 
     optionsamount+= parseFloat(optprice);  
    }) 

    var qty = $(this).find('.qty option:selected').val(); 
    var price = $(this).find('.price').val(); 
    var amount = (qty*price); 
    sum+= (amount + optionsamount); 

    $(this).find('.amount').text(''+ amount.toFixed(2)); 
}); 

$('.total').text(sum); 
+0

Vaivhav hesaplar, adam gibisin! :) büyük teşekkür ederim! Yanlış olan ne oldu? – Europeuser

+1

jquery selector ('.selectedoptionselect seçenek: selected') tüm ürünler için her zaman çalışıyordu ... – Vaibhav

+0

Bir kez daha Teşekkürler Vaibhav! – Europeuser

0

siz) (işlev `update_amounts hiç aramıyorsun, bu

function update_amounts(){ 
var sum = 0.0; 

$('#basketorder > tbody > .product').each(function() { 

    var optionsamount = 0.0; 


    $('.selectedoptionselect option:selected').each(function(){ 
     optprice = $(this).attr('price'); 
     optionsamount+= parseFloat(optprice);  
    }) 

    var qty = $(this).find('.qty option:selected').val(); 
    var price = $(this).find('.price').val(); 
    var amount = (qty*price); 
    sum+= (amount + optionsamount); 

    $(this).find('.amount').text(''+ amount.toFixed(2)); 
}); 

$('.total').text(sum); 

}

+0

Alex hala double optionsamount – Europeuser

İlgili konular