选民投票后,我想更新计数。
<form class="vote-form" action="">
<div id="{{key}}" class="vote-count">{{votes}}</div>
<input class="vote-button" type="submit" class="text-button" value="vote+"/>
<input type="hidden" class="brag" name="brag" value="{{key}}">
<input type="hidden" class="voter" name="voter" value="{{current_user.fb_id}}">
</form>
<script type="text/javascript">
$(function() {
$('.error').hide();
$(".vote-form").submit(function() {
var inputs = $(this).find('input:hidden');
var key = $('input.brag', this).val();
$.ajax({
type: "POST",
url: "/bean",
data: inputs,
success: function() {
//not sure how to do this, I want to increment {{votes}}
$('#' + key).innerHTML = "foo";
}
});
return false;
});
});
</script>
最佳答案
var $div = $('#' + key),
intValue = parseInt($div.html(), 10);
$div.html(++intValue);
关于javascript - 如何通过javascript更新html中的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4630487/