Javascript 更改时更新价格,包括选择

Javascript 更改时更新价格,包括选择,javascript,jquery,select,calc,Javascript,Jquery,Select,Calc,这是我的小提琴: 当我输入数量时,我会自动计算价格。 我还希望包括正在添加的选择选项 每1个数量1英镑 如果有人输入10数量-价格应为10数量*(1*10英镑)*价格 当前当我添加: // update price if option change var optionprice = 0; var getPriceOption = function() { jQuery("#select_21").change(function() { if (jQuery(this).

这是我的小提琴:

当我输入数量时,我会自动计算价格。
我还希望包括正在添加的选择选项
每1个数量1英镑

如果有人输入10数量-价格应为10数量*(1*10英镑)*价格

当前当我添加:

 // 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中更改

这就足够了:

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)
         }
       }

您是否关闭了
获取价格选项的
()
?因为它应该作为函数记录,而不是未定义。如果您这样做了,则结果是未定义的,因为在发生更改之前,
optionprice
不会被定义。因此,基本上您希望根据下拉更改执行操作自动价格计算?我更新了jsfidlle,因为它不起作用。当我们键入其更新编号时@Taplar应该有optionprice,但它无论如何都不起作用。积山-它现在自动更新类型号,但应该包括下拉列表。