计算表单具有选项,并根据客户端输入的内容确定侧边栏中加载的产品。产品的数量直接反映了期权的价值。
所以现在每个产品都有一个总价格,总持续时间和总潜水次数,如这里所示。
num1=Number(document.getElementById('product_quantity_' + productid).value);
num2=Number(document.getElementById('product_price_' + productid).value);
nums=num1*num2;
document.getElementById('product_price_total_' + productid).value = nums;
num1=Number(document.getElementById('product_quantity_' + productid).value);
num2=Number(document.getElementById('product_duration_' + productid).value);
nums=num1*num2;
document.getElementById('product_duration_total_' + productid).value = nums;
num1=Number(document.getElementById('product_quantity_' + productid).value);
num2=Number(document.getElementById('product_dives_' + productid).value);
nums=num1*num2;
document.getElementById('product_dives_total_' + productid).value = nums;
num1=Number(document.getElementById('product_quantity_' + productid).value);
num2=Number(document.getElementById('product_hire_' + productid).value);
nums=num1*num2;
document.getElementById('product_hire_total_' + productid).value = nums;所以现在我们需要一个脚本来给我们提供所有-- 'product_price_total_‘+ productid).value的总价格--另一个是总持续时间,第三个是总潜水等等。等等。
不知道怎么做,但有几个想法可能是一个数组,它只将字段与特定的alt标签或title标签相加。
谁有什么想法。
谢谢
发布于 2010-12-01 08:30:30
像这样怎么样?(使用与上述Šime Vidas相同的$()函数)
var productIds = {};
function product_totals(id) {
productIds[id] = true; // store all id's as the totals are calculated
....
}
function totalTotals() {
var totalPriceTotal = 0;
var totalDurationTotal = 0;
var totalDivesTotal = 0;
var totalHireTotal = 0;
for (var id in productIds) {
// multiply by 1 to make sure it's a number
totalPriceTotal += $('product_price_total_' + id).value*1;
totalDurationTotal += $('product_duration_total_' + id).value*1;
totalDivesTotal += $('product_dives_total_' + id).value*1;
totalHireTotal += $('product_hire_total_' + id).value*1;
}
}发布于 2010-12-02 22:23:27
非常棒的工作伙伴们,谢谢你们的帮助。非常好的团队合作,这里是完整的最终代码。
function product_analysis(地址,盒子){ if (box.checked) {
$('#product_' + box.alt).load(address);
}
else {
$('#product_' + box.alt).load('http://www.divethegap.com/update/blank.html');
}
document.getElementById('product_quantity_PRI_' + box.alt).value = box.value;};
var productIds = {};
函数product_totals(id) { productIdsid = true;//将所有id存储为合计计算var quantity = $c('product_quantity_‘+ id).value;var price = $c('product_price_’+ id).value;var duration = $c('product_duration_‘+ id).value;var dives = $c('product_dives_’+ id).value;var hire = $c('product_hire_‘+ id).value;
Number($c('product_price_total_' + id).value = price * quantity);
Number($c('product_duration_total_' + id).value = duration * quantity);
Number($c('product_dives_total_' + id).value = dives * quantity);
Number($c('product_hire_total_' + id).value = hire * quantity);
function $c(id) {
return document.getElementById(id);}
}
函数totalTotals() { var totalPriceTotal = 0;var totalDurationTotal = 0;var totalDivesTotal = 0;var totalHireTotal = 0;
for (var id in productIds) {
// multiply by 1 to make sure it's a number
totalPriceTotal += $c('product_price_total_' + id).value*1;
totalDurationTotal += $c('product_duration_total_' + id).value*1;
totalDivesTotal += $c('product_dives_total_' + id).value*1;
totalHireTotal += $c('product_hire_total_' + id).value*1;
}
$c('GT_total_price').value = totalPriceTotal;
$c('GT_total_duration').value = totalDurationTotal;
$c('GT_total_dives').value = totalDivesTotal;
$c('GT_total_hire').value = totalHireTotal;
function $c(id) {
return document.getElementById(id);}
}
https://stackoverflow.com/questions/4319613
复制相似问题