繁体   English   中英

为什么使用onclick和切换后我的购物车总额不起作用?

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

以下是指向我的问题儿童购物车的链接:http: //CODEX32.com/simpleShoppingCart,带有一个链接,可在页面左上角查看其页面来源。

具体的问题是运行总计不能正常工作。 任何方向将不胜感激。 先感谢您。

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

进行consol.log(window.sku2976Total)显示window.sku2976Totalundefined

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

因此,可以将变量开头设置为0,或者在使用变量之前检查变量是否已定义。

您可以这样做:

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

要么

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM