我得到以下代码在本地工作,但是当我将它推送到开发服务器时,它会中断。 它说bxSliderInstances [“slider”+ index]实例是未定义的,但是当我在localhost上检查它时它被定义。我有什么想法可以改进这个脚本?我绝对是个初学者。谢谢!
$(function(){
// GALLERY
var $slider = $('.bxslider');
var bxSliderInstances = {};
function insertCount(index, element) {
console.log(bxSliderInstances["slider" + index]);
var slide_count = bxSliderInstances["slider" + index].getSlideCount();
var slide_curr = bxSliderInstances["slider" + index].getCurrentSlide();
$(bxSliderInstances["slider" + index]).find('.image-count').hide();
$(bxSliderInstances["slider" + index]).find('.bx-caption').append('<span class="image-count">' + (slide_curr + 1) + '/' + slide_count + '</span>');
};
// For each result
$slider.each(function (index, element) {
// Initialise a slider using the current index value
bxSliderInstances["slider" + index] = $slider.eq(index).bxSlider({
auto: false,
pagerCustom: '#bx-pager' + [index],
captions: true,
onSliderLoad: function (){
insertCount(index, element);
},
onSlideAfter: function(){
insertCount(index, element);
}
});
});
});