这是我的网站http://iadprint.com/products?product=product%201
当您为attribute19k选择下拉列表时,价格值会发生变化。但是当你选择其他选择时没有任何反应。如果你看看底部的源方式是我放的js。应该发生的是每次选择一个选择时,该值会累计到总变量并显示在定价范围内。但我不明白为什么它不起作用。变量已分配,但未进行任何计算。谁能看到我看不到的东西?
感谢
ps这里是js
var woattribute19k_price;
var woattribute2_price;
var woattribute3_price;
var woattribute4_price;
var woattribute5_price;
$(document).ready(function() {
$("#attribute19k").change(function()
{
hash = $("#attribute19k").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute19k_price = out.price;
displayPrice();
}, "json");
});
$("#attribute2").change(function()
{
hash = $("#attribute2").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute2_price = out.price;
displayPrice();
}, "json");
});
$("#attribute3").change(function()
{
hash = $("#attribute3").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute3_price = out.price;
displayPrice();
}, "json");
});
$("#attribute4").change(function()
{
hash = $("#attribute4").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute4_price = out.price;
displayPrice();
}, "json");
});
$("#attribute5").change(function()
{
hash = $("#attribute5").val();
$.get("ajax.php", { id: hash },
function(out)
{
woattribute5_price = out.price;
displayPrice();
}, "json");
});
});
function displayPrice()
{
var total = 0;
var qattribute19k = parseFloat((woattribute19k_price != null) ? woattribute19k_price : 0);
total = parseFloat(total + qattribute19k).toFixed(2);
var qattribute2 = parseFloat((woattribute2_price != null) ? woattribute2_price : 0);
total = parseFloat(total + qattribute2).toFixed(2);
var qattribute3 = parseFloat((woattribute3_price != null) ? woattribute3_price : 0);
total = parseFloat(total + qattribute3).toFixed(2);
var qattribute4 = parseFloat((woattribute4_price != null) ? woattribute4_price : 0);
total = parseFloat(total + qattribute4).toFixed(2);
var qattribute5 = parseFloat((woattribute5_price != null) ? woattribute5_price : 0);
total = parseFloat(total + qattribute5).toFixed(2);
$("#pricing span").text('$' + total);
}
答案 0 :(得分:0)
您必须仅在displayPrice
的末尾使用toFixed