我有一组问题,想在它们上方显示一个简单的进度计数器。下面的代码工作正常,但我想知道是否有人可以就重构提出建议,因为必须有更好的方法来实现这一点。
var totalCount = $('#questions li').length,
count = 1;
$('.progress').html("Question " + count + " of " + totalCount);
// Increment by 1 on each click
$('.btn-next').click(function(){
count ++ ;
// remove current count
$('.progress').empty();
// drop in new count
$('.progress').html("Question " + count + " of " + totalCount);
});
// Decrease by 1 on each click
$('.btn-prev').click(function(){
count -- ;
// remove current count
$('.progress').empty();
// drop in new count
$('.progress').html("Question " + count + " of " + totalCount);
});