为什么我的购物车总数无法使用 onclick 和 toggle 工作?

Why does my shopping cart total not work using onclick and toggle?

这是我的问题儿童购物车的 link:http://CODEX32.com/simpleShoppingCart 带有 link 以在页面左上角查看其页面源代码。

具体问题是 运行 总数无法正常工作。任何方向将不胜感激。提前谢谢你。

try {
function grandTotal() {     
running_total = window.sku9448Total + window.sku2976Total;
document.getElementById('total').value = '$' + running_total;
}
} catch(e) {}

做一个 consol.log(window.sku2976Total) 显示 window.sku2976Totalundefined

您的问题是变量在您尝试访问它们时未定义,因此结果导致 undefined 变量在附加时显示为 NaN

所以,要么将开头的变量设置为0,要么在使用之前检查变量是否定义。

你可以这样做:

if(typeof variable_here === 'undefined'){
   // your code here.
};

if(! variable_here){
   // your code here.
};