我的脚本正在返回 NAN,我希望它改为显示 0。
使用 || 0 已经实现了这一点,但是它现在返回 100 而不是 var percentQ 的 0。是什么导致它返回 100?
$('#observationTotalRefresh').on('click', function () {
var
sumP = 0,
sumQ = 0,
countP = 0,
countQ = 0;
$('.observationPositive:not(:disabled)').each(function(){
countP++;
sumP += Number($(this).val());
});
$('.observationQuestionable:not(:disabled)').each(function(){
countQ++;
sumQ += Number($(this).val());
});
var percentP = 100/(1 + (sumQ/sumP)) || 0;
var percentQ = (100 - percentP) || 0;
$("#observationPositivePercentage").text(percentP.toFixed(0));
$("#observationQuestionablePercentage").text(percentQ.toFixed(0));
$("#observationTotal").text(sumP + sumQ);
});