Jquery 为什么不是';在数量超过2之前,我的动态价格不起作用吗?

Jquery 为什么不是';在数量超过2之前,我的动态价格不起作用吗?,jquery,Jquery,我正在将动态价格构建到magento产品页面中,当数量增加或减少时,我遇到了一些数量增加/减少按钮的问题。价格将改变以反映新的价格 当数量超过3、5或10时,我的计算会改变基价,所以这不是问题,这是事实,当数量为2时,它反映了价格,但它在1上 任何想法都会很棒 //数量按钮 var upBtn=jQuery(“#btn数量增加”); var downBtn=jQuery(“#btn数量减少”); var currentQty=document.getElementById(“数量扩展”); v

我正在将动态价格构建到magento产品页面中,当数量增加或减少时,我遇到了一些数量增加/减少按钮的问题。价格将改变以反映新的价格

当数量超过3、5或10时,我的计算会改变基价,所以这不是问题,这是事实,当数量为2时,它反映了价格,但它在1上

任何想法都会很棒

//数量按钮
var upBtn=jQuery(“#btn数量增加”);
var downBtn=jQuery(“#btn数量减少”);
var currentQty=document.getElementById(“数量扩展”);
var数量=当前数量值;
如果(数量<2){
}
downBtn.单击(函数(){
var currentQty=document.getElementById(“数量扩展”);
var数量=当前数量值;
//控制台日志(数量);
//console.log('down');
如果(!isNaN(数量)&数量>0){
当前数量值--;
//声明的变量
var newPrice=jQuery(“#动态#u定价”).find('h1');
var screwinput=jQuery('select#attribute186')。查找(“:selected”).text();
var calPrice;
QtyPrice变种;
//如果数量为空或为空,则发出警告并停止
/*如果(数量长度===0 | |数量===''){
//warnings.show().html('Quantity Missing')、delay(3000)、fadeOut(500);
停止();
} */
//如果数量大于X,则价格为X
开关(真){
案例(数量=3和数量=5和数量=10):
QtyPrice='10.95';
打破
}
//如果(输入=否){
计算价格=(数量价格*数量);
//}否则{
//计算价格=((1.95*数量)+(数量价格*数量));
//}
newPrice.html(“£”+calPrice.toFixed(2));
}         
返回false;
});
向上单击(函数(){
var currentQty=document.getElementById(“数量扩展”);
var数量=当前数量值;
//控制台日志(数量);
//console.log('up');
如果(!isNaN(数量)){
当前数量值++;
//声明的变量
var newPrice=jQuery(“#动态#u定价”).find('h1');
var screwinput=jQuery('select#attribute186')。查找(“:selected”).text();
var calPrice;
QtyPrice变种;
//如果数量为空或为空,则发出警告并停止
/*
如果(数量长度===0 | |数量===''){
//warnings.show().html('Quantity Missing')、delay(3000)、fadeOut(500);
停止();
} */
//如果数量大于X,则价格为X
开关(真){
案例(数量=3和数量=5和数量=10):
QtyPrice='10.95';
打破
}
//如果(输入=否){
计算价格=(数量价格*数量);
//}否则{
//计算价格=((1.95*数量)+(数量价格*数量));
//}
newPrice.html(“£”+calPrice.toFixed(2));
}
返回false;
})
Change
calPrice=(数量价格*数量)至<代码>计算价格=(数量价格*当前数量值)与另一个相同

//QUANTITY BUTTONS

var upBtn = jQuery('#btn-qty-up');
var downBtn = jQuery('#btn-qty-down');
var currentQty = document.getElementById('qty_extention'); 
var qty = currentQty.value; 
if(qty < 2){

}
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 EMPTY OR NULL GIVE WARNING AND STOP
        /*if(qty.length === 0 || qty === ''){
            //warnings.show().html('Quantity Missing').delay(3000).fadeOut(500);
            stop();
        } */

        //IF QUANTITY IS MORE THAN X THEN PRICE IS X
        switch(true) {
            case (qty <= 2):
                QtyPrice = '12.95';
                break;
            case (qty >=3 && qty <= 4):
                QtyPrice = '12.30';
                break;
            case (qty >=5 && qty <= 9):
                QtyPrice = '11.65';
                break;
            case (qty >=10):
                QtyPrice = '10.95';
                break;
        }

        //if(screwinput == 'No') {
            calPrice = (QtyPrice * qty);
        //} else {
        //   calPrice = ((1.95 * quantity) + (QtyPrice * quantity));
        //}

        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 EMPTY OR NULL GIVE WARNING AND STOP
        /*
        if(qty.length === 0 || qty === ''){
            //warnings.show().html('Quantity Missing').delay(3000).fadeOut(500);
            stop();
        } */

        //IF QUANTITY IS MORE THAN X THEN PRICE IS X
        switch(true) {
            case (qty <= 2):
                QtyPrice = '12.95';
                break;
            case (qty >=3 && qty <= 4):
                QtyPrice = '12.30';
                break;
            case (qty >=5 && qty <= 9):
                QtyPrice = '11.65';
                break;
            case (qty >=10):
                QtyPrice = '10.95';
                break;
        }

        //if(screwinput == 'No') {
            calPrice = (QtyPrice * qty);
        //} else {
        //   calPrice = ((1.95 * quantity) + (QtyPrice * quantity));
        //}

        newPrice.html('£' + calPrice.toFixed(2));
    }




    return false;
})