Ich habe eine Menge Box auf meiner Produktseite, dass, wenn Sie die Menge erhöhen oder verringern eine Box hervorheben, welchen Rabatt Sie erhalten, aber aus irgendeinem Grund hebt es 3 Pack oder mehr, wenn es auf 4 sogar meine Berechnung zu markieren wann die Menge ist> = 3Warum markiert es nicht an der richtigen Nummer?
mein Code:
//QUANTITY BUTTONS
var upBtn = jQuery('#btn-qty-up');
var downBtn = jQuery('#btn-qty-down');
var currentQty = document.getElementById('qty_extention');
var priceTable = jQuery('#multibuy table');
var qty = currentQty.value;
downBtn.click(function(){
var currentQty = document.getElementById('qty_extention');
var qty = currentQty.value;
//console.log(qty);
//console.log('down');
if(!isNaN(qty) && qty > 0){
currentQty.value--;
//VARIBLES DECLARED
var newPrice = jQuery('#dynamic_pricing').find('h1');
var screwinput = jQuery('select#attribute186').find(":selected").text();
var calPrice;
var QtyPrice;
//IF QUANTITY IS MORE THAN X THEN PRICE IS X
switch(true) {
case (qty <= 2):
QtyPrice = '12.95';
priceTable.find('tr:first-child').css('background', 'none');
break;
case (qty >=3 && qty <= 4):
QtyPrice = '12.30';
priceTable.find('tr:first-child').css('background', '#ccc');
priceTable.find('tr:nth-child(2)').css('background', 'none');
break;
case (qty >=5 && qty <= 9):
QtyPrice = '11.65';
priceTable.find('tr:first-child').css('background', 'none');
priceTable.find('tr:nth-child(2)').css('background', '#ccc');
priceTable.find('tr:nth-child(3)').css('background', 'none');
break;
case (qty >=10):
QtyPrice = '10.95';
priceTable.find('tr:nth-child(2)').css('background', 'none');
priceTable.find('tr:nth-child(3)').css('background', '#ccc');
break;
}
jQuery('#qty').val(currentQty.value);
calPrice = (QtyPrice * currentQty.value);
newPrice.html('£' + calPrice.toFixed(2));
}
return false;
});
upBtn.click(function(){
var currentQty = document.getElementById('qty_extention');
var qty = currentQty.value;
//console.log(qty);
//console.log('up');
if(!isNaN(qty)) {
currentQty.value++;
//VARIBLES DECLARED
var newPrice = jQuery('#dynamic_pricing').find('h1');
var screwinput = jQuery('select#attribute186').find(":selected").text();
var calPrice;
var QtyPrice;
//IF QUANTITY IS MORE THAN X THEN PRICE IS X
switch(true) {
case (qty <= 2):
QtyPrice = '12.95';
priceTable.find('tr:first-child').css('background', 'none');
break;
case (qty >=3 && qty <= 4):
QtyPrice = '12.30';
priceTable.find('tr:first-child').css('background', '#ccc');
priceTable.find('tr:nth-child(2)').css('background', 'none');
break;
case (qty >=5 && qty <= 9):
QtyPrice = '11.65';
priceTable.find('tr:first-child').css('background', 'none');
priceTable.find('tr:nth-child(2)').css('background', '#ccc');
priceTable.find('tr:nth-child(3)').css('background', 'none');
break;
case (qty >=10):
QtyPrice = '10.95';
priceTable.find('tr:nth-child(2)').css('background', 'none');
priceTable.find('tr:nth-child(3)').css('background', '#ccc');
break;
}
jQuery('#qty').val(currentQty.value);
calPrice = (QtyPrice * currentQty.value);
newPrice.html('£' + calPrice.toFixed(2));
}
return false;
});
hier ist es in Aktion:
ich meine Berechnung ein bisschen off haben Jede Hilfe würde sehr geschätzt werden.
Da für '3'' £ 38,95' angezeigt wird, was nicht diskontiert ist, aber offensichtlich ein Vielfaches des Preises für drei Elemente ist, scheint es so, als ob'qt' aktualisiert * wird, nachdem der Schalter ausgeführt wurde. aber * bevor * der Endpreis festgelegt wird. An welchem Ereignis wird der Schalter ausgelöst? –
Da Sie nur zwei Optionen haben, versuchen Sie 'Qty === 3 || Menge === 4' –
Das sind Variablenzuweisungen, @Darren, und die wahrscheinliche Ursache ist hier nicht, dass '> =' in der JavaScript-Engine von OP gebrochen wäre. Sie führen Fehler ein, ohne sie zu lösen. –