我正在教自己如何使用Bootstrap建立一个网站,我试图通过一个Upvote和一个Downvote按钮递增和递减进度条。我想获得该酒吧的当前价值,所以我想我会从aria-valuenow中撤回它。我在Javascript / jQuery上相当新,我无法理解它。
我到目前为止:
var currScore = $('#myProgressBar').attr('aria-valuenow');
$(function() {
$('#upvote').on('click', function () {
var newScore = currScore++;
});
$('#downvote').on('click', function () {
var newScore = currScore--;
});
$('#myProgressBar').attr('aira-valuenow', newScore).css('width', newScore+'%');
});
任何帮助都将受到高度赞赏,谢谢!
答案 0 :(得分:0)
解析currScore值
var currScore = $('#myProgressBar').attr('aria-valuenow');
currScore = parseInt(currScore,10);
$(function() {
$('#upvote').on('click', function () {
var newScore = currScore++;
});
$('#downvote').on('click', function () {
var newScore = currScore--;
});
$('#myProgressBar').attr('aira-valuenow', newScore).css('width', newScore+'%');
});