2014-10-01 58 views
1

我使用此脚本滑块:当图像的数量超过9.引导传送带与缩略图超过9项

缩略图数10重定向到滑动0

数11滑动 http://www.bootply.com/79859 问题出现1

数12滑动2
...

什么是错的代码?

$('#myCarousel').carousel({ 
    interval: 4000 
}); 

// handles the carousel thumbnails 
$('[id^=carousel-selector-]').click(function(){ 
    var id_selector = $(this).attr("id"); 
    var id = id_selector.substr(id_selector.length -1); 
    id = parseInt(id); 
    $('#myCarousel').carousel(id); 
    $('[id^=carousel-selector-]').removeClass('selected'); 
    $(this).addClass('selected'); 
}); 

// when the carousel slides, auto update 
$('#myCarousel').on('slid', function (e) { 
    var id = $('.item.active').data('slide-number'); 
    id = parseInt(id); 
    $('[id^=carousel-selector-]').removeClass('selected'); 
    $('[id=carousel-selector-'+id+']').addClass('selected'); 
}); 
+0

它的'可能不是这段代码是错误的。给我们展示你的html怎么样? – 2014-10-01 09:12:26

回答

1

问题是这样的线:

var id = id_selector.substr(id_selector.length -1); 

它是假设的数目的长度为1个字符长。改为改为此。此版本刚刚在最后一个位置-后面开始:

var id = id_selector.substr(id_selector.lastIndexOf("-")+1);