1
我正在使用這一位代碼來添加表列中的值,其中 工作得很好,直到它遇到具有 值的空td單元格爲止。從循環中的這一點開始,我的 警報中收到NaN錯誤。我想知道如何忽略這些非數字值,或者將其替換爲零來計算?列總NAN錯誤
jQuery(function() {
var MarketCapTotal = 0;
// loop through the table
jQuery('#grdWatchlistname tbody tr').each(function() {
// replace the dollar signs and commas
var MarketCap = (jQuery('td:nth-child(4)', jQuery(this)).html
().replace('$', '').replace(/[^a-zA-Z 0-9]+/g, ''));
var td4th = jQuery('td:nth-child(4)', jQuery(this));
MarketCapTotal += parseInt(MarketCap);
alert(MarketCapTotal);
});
});