gpt4 book ai didi

javascript - jQuery计算价格不起作用(正确)

转载 作者:行者123 更新时间:2023-12-03 12:38:36 28 4
gpt4 key购买 nike

$(function() {

var base_price = 0;
CalculatePrice();

$(".math1").on('change', function(e) {
CalculatePrice();
});


function CalculatePrice() {
var base_cost = base_price;
$('.math1').each(function() {
base_cost += $(this).find('option:selected').data("price");
});
$("#price").text(base_cost.toFixed(2)*32);
}


});

该脚本将查看所选选项的所有数据价格并执行以下操作:
data-price (of select 1) + data-price (of select 2)

但它需要这样做:
data-price (of select 1) * data-price (of select 2)

它将返回一个标准值,例如:
2 person room = $32, 2 2 person rooms = $64 (correctly)
4 person room = $64, 2 4 person rooms = $96 (must be + 64 instead of 32 so will return $128)
6 persoon room = $128, 2 6 person rooms= $160 (must be +128 so will return $256)

fiddle : http://jsfiddle.net/5HkEh/3/

注意:这不起作用
base_cost *= $(this).find('option:selected').data("price");

最佳答案

设置 base_price = 1
然后更改您的+=*=

关于javascript - jQuery计算价格不起作用(正确),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23614971/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com