나는 jQuery를 사용하여 간단한 계산을 수행하려하지만 결과로 NaN을 얻고 있습니다.parseInt html string value
$(document).on('click','.button-group button:not(.done)', function(e){
e.preventDefault();
$(this).addClass('active');
var votevalue = $(this).data('votevalue');
var image_id = $('.mainimage').data('image_id');
var votes = $('.mainimage').data('numvotes');
var totalscore = $('.mainimage').data('totalscore');
$.ajax({
type: 'POST',
url: '?a=vote',
data: {
"votevalue" : votevalue,
"image_id" : image_id
},
success: function(){
var votes = parseInt(votes);
votes++;
var average = ((parseInt(totalscore) + parseInt(votevalue))/votes);
$('#vote-incremenet').html(votes);
$('#display-average').html(average);
$('#display-average').show();
$('.button-group button').addClass('done');
}
}); // end ajax
}); // end click
내가 잘못 뭐하는 거지 : 여기
내 자바 스크립트입니까?
'NaN' 문제와 관련이 없으므로 새로운'votes' 값을'$ ('. mainimage')에 다시 저장하면 안됩니까? data ('numvotes')'? 그렇지 않으면 다른 버튼을 클릭 할 때 이전 numvotes 값을 계산에 사용합니다. – nnnnnn
다음 이미지까지 사용자가 처음 선택한 후에 모든 버튼이 비활성화되지 않습니다 (.addClass ('done')). – user1683645