【问题标题】:Update price on change inlcuding on select更新价格的变化,包括选择
【发布时间】:2020-03-23 13:24:08
【问题描述】:

这是我的小提琴: 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 中更改。

【问题讨论】:

  • 您是否将()getPriceOption 分开?因为那应该作为函数记录,而不是未定义的。如果你这样做了,结果是未定义的,因为 optionprice 在更改发生之前不会被定义。
  • 那么基本上你想根据下拉菜单的变化进行操作自动价格计算?
  • 我更新了 jsfidlle 因为没有工作。当我们输入 qty 时,它的更新编号。 @Taplar 应该有 optionprice,但它无论如何都不起作用。 Jishan - 它现在自动更新类型编号,但应包括下拉菜单。

标签: javascript jquery select calc


【解决方案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)
         }
       }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 2017-12-08
    • 1970-01-01
    相关资源
    最近更新 更多