Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery JS在本地主机上定义,但在远程主机上未定义_Jquery - Fatal编程技术网

Jquery JS在本地主机上定义,但在远程主机上未定义

Jquery JS在本地主机上定义,但在远程主机上未定义,jquery,Jquery,我让下面的代码在本地工作,但是当我把它推到dev服务器上时,它就崩溃了。 它说bxSliderInstances[“slider”+index]实例未定义,但在本地主机上检查时定义了它。有什么办法可以改进这个脚本吗?我绝对是个初学者。谢谢 $(function(){ // GALLERY var $slider = $('.bxslider'); var bxSliderInstances = {}; function insertCount(index, ele

我让下面的代码在本地工作,但是当我把它推到dev服务器上时,它就崩溃了。 它说bxSliderInstances[“slider”+index]实例未定义,但在本地主机上检查时定义了它。有什么办法可以改进这个脚本吗?我绝对是个初学者。谢谢

$(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);
         }
     });
   });

 });
$(函数(){
//画廊
变量$slider=$('.bxslider');
var bxSliderInstances={};
函数insertCount(索引,元素){
log(bxSliderInstances[“slider”+索引]);
var slide_count=bxSliderInstances[“slider”+索引].getSlideCount();
var slide_curr=bxSliderInstances[“slider”+索引].getCurrentSlide();
$(bxSliderInstances[“slider”+index]).find('.image count').hide();
$(bxSliderInstances[“slider”+index])。查找('.bx标题')。追加(''+(slide\u curr+1)+'/'+slide\u count+'');
};
//对于每个结果
$slider.each(函数(索引、元素){
//使用当前索引值初始化滑块
bxSliderInstances[“slider”+index]=$slider.eq(index).bxSlider({
汽车:错,
pagerCustom:“#bx寻呼机”+[index],
标题:对,
onSliderLoad:函数(){
insertCount(索引、元素);
},
onSlideAfter:function(){
insertCount(索引、元素);
}
});
});
});

您可能遇到范围问题。相反,请尝试使函数接受滑块,但使用不同的名称。重构如下:
insertCount(索引、元素、滑块)
。然后将这两个调用更改为:
insertCount(索引、元素、bxSliderInstances)你确定你已经在开发服务器上上传了jquery.bxslider.min.js文件吗?谢谢你的建议!我尝试了范围修复,但仍然遇到同样的问题。我还确认插件js文件在dev服务器上。我相信我已经找到了问题所在。onSliderLoad在插件脚本准备就绪之前运行。我已经将setTimeout(3000)添加到它里面的函数中,现在它可以工作了。这并不理想,因为现在画廊柜台的显示有延迟。但总比打破它好。我会继续寻找解决办法。