2
누계를 유지해야하는 변수가 있습니다. 이 루프의 각 단계에서 누적 금액에 금액을 추가해야합니다. 내가 정의되지 않았거나 NaN을 얻었 기 때문에 나는 뭔가를 놓쳤을 것입니다.jquery 루프에서 누적 합계에 숫자 추가
var totalSqft = 0;
그렇지 않으면,이 undefined
으로 초기화됩니다 및 undefined
+ 숫자는 NaN
입니다 :
$('#btnSubmit').click(function(e) {
var totalSqft;
$('.fieldset').each(function() {
var sqft;
var width = $(this).find('input:eq(0)').val();
var height = $(this).find('input:eq(1)').val();
var type = $(this).find('select').val();
if (type == 'tri') {
sqft = (width * height)/2;
} else {
sqft = (width * height);
};
totalSqft += sqft;
alert('this ' + type + ' is ' + width + ' wide and ' + height + ' high, for a total of ' + sqft + ' square feet');
});
alert('Done. Total Sq Ft is ' + totalSqft);
})
문자열과 동일하지만 누군가가 알지 못하는 경우를 대비하여 – ajax333221