更新价格的变化,包括选择

这是我的小提琴: https ://jsfiddle.net/btekbtek/6gxztk4f/6/


当我输入数量时,我会自动计算价格。

我还想包括

每 1 数量增加 1 英镑的选择选项。


如果有人输入 10 数量 - 价格应该是 qty10*(£1*10)*price


目前当我添加:


 // update price if option change

 var optionprice = 0;

 var getPriceOption = function() {

   jQuery("#select_21").change(function() {

     if (jQuery(this).val() === '63') {

       optionprice = 0;

     } else {

       optionprice = 1;

     }

   }); //end update optionprice

   return optionprice;

 }; //end get PriceOption


 console.log(getPriceOption);

getPriceOption 未定义。我试图在之前和相同的结果之后添加它。


我无法更改 HTML 中的任何内容,只能在 jQuery 中更改。


白猪掌柜的
浏览 141回答 1
1回答

侃侃尔雅

这已经足够了:var updateprice = $("#select_21 option:selected").attr('price');添加在:while (i--) {         if (qty >= tierPrices[i]['price_qty']) {           var updateprice = $("#select_21 option:selected").attr('price');           var calc_price = tierPrices[i]['price'] * qty + (updateprice*qty);           return (calc_price).toFixed(2)         }       }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript