Iveは私の商品ページに数量ボックスを持っています。あなたが数量を増減すると、どの割引が得られるかがボックスで強調されますが、何らかの理由で3パック以上が強調表示されます。量は> = 3なぜそれが正しい番号で強調表示されていませんか?
私のコードです:
//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;
});
ここではアクションである:
私は少しオフ私の計算であってもよいですどんな助けでも大歓迎です。
「3」の場合、割引なしの「£38,95」が表示されますが、明らかに3つのアイテムの価格の倍数であると、スイッチが実行された後に* qtyが更新されるようです。 *前に*最終価格が設定されています。どのイベントがスイッチでトリガーされましたか? –
2つのオプションしかないので、 'qty === 3 || qty === 4' –
これは変数代入@Darrenであり、OPのjavascriptエンジンでは '> ='が壊れることはありません。あなたは何も解決せずにエラーを導入しています。 –