0

我用 jquery 来获取计数是

var currentPosition = 0;
var slides = $(".slideritem");
var numberOfSlides = slides.length;

manageControls(currentPosition);
function manageControls(position){
var count = document.getElementById("count");
count.innerHTML =(position + 1) + "/" + numberOfSlides;
  }

这是我的JSFiddle。它显示计数,但当我转到下一个 div 时它不会更新。有什么解决办法吗?

4

2 回答 2

1

你错过了一个电话manageControls()......你可以把它放在这里:

$('li').click(function() {
    var index = $(this).index();
    setActive(index);
    manageControls(index);
});
于 2012-08-25T07:27:14.257 回答
0
var currentPosition = 0;
 var slides = $(".myclass");
 var numberOfSlides = slides.length;

 manageControls(currentPosition);
 function manageControls(position){
 var count = document.getElementById("count");
 count.innerHTML =(position + 1) + "/" + numberOfSlides;
 }

 setActive(0);

$('li').click(function() {
setActive($(this).index());
manageControls($(this).index());

});

  $(".next").click(function(){
   var current = $('ul li.selected').index(),
    maxIndex = $('ul li').length - 1,
    next = (current + 1) >  maxIndex ? 0 : (current + 1);
   manageControls(next);
   setActive(next);

  });

 function setActive(i) {
var li = $('ul li').eq(i);

$('ul li').removeClass('selected');
li.addClass('selected');
$('.myclass').removeClass('selected');
$('.myclass').eq(i).addClass('selected');
 }
于 2012-08-25T07:37:13.687 回答