javascript - IE8 特定的 JavaScript 错误?

标签 javascript jquery internet-explorer-8

我在 IE8 中遇到问题:

function costructor(sectionId){
$('#nextG').ready(function(){
var counterBis = 0;
slider = '.slider0'+sectionId;
//sliderBox = $(slider).closest('.floatContent');
unitScrollBis = $(slider).find('.floatImg').eq(0).width();
maxImg = $(slider).find('.floatImg').length-2;
    /*problem*/
prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
    /*END*/
console.log(prev);
console.log(next);
makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg);
function makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg){
if(counterBis <= 0){
    $(prev).fadeOut("fast");
}
else if(counterBis >= maxImg){
    $(next).fadeOut("fast");
}
$(next).click(function(){
    if(counterBis <= maxImg){
        counterBis++;
        $(prev).fadeIn("fast");
        slide(counterBis);
        }
    else{
        $(next).fadeOut("fast");
    }
});
$(prev).click(function(){
    if(counterBis > 0){
        counterBis--;
        $(next).fadeIn("fast");
        slide(counterBis);
    }
    else{
        $(prev).fadeOut("fast");
    }
});
function slide(counterBis){
    $(slider).animate({
    marginLeft: '-' + (unitScrollBis*counterBis) + 'px'
},1000);
};
};

IE8 说:SCRIPT438: 对象不支持属性或方法 谁能帮帮我? 问题只出现在 IE8 中,我不明白为什么 IE 无法构建此字符串。 谢谢你的帮助

最佳答案

您需要使用 var 关键字声明变量,否则旧版本的 IE 将无法识别它们并可能中断。

所以改变

prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");

var prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
var next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");

一切都应该像在其他浏览器/IE9 中一样工作

关于javascript - IE8 特定的 JavaScript 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13586357/

相关文章:

jquery - 当另一个有内容时,如何隐藏一个 div 类

c# - 商店通用应用程序上的 WebClient

c++ - 使用 IOpenServiceManager::InstallService 设置 IE 的默认搜索引擎提供程序

javascript - 增量循环

javascript - 动态生成集成参数的函数数组?

javascript - 在 angularjs 中获取数据到 $scope 失败

javascript - CSS 规则未按预期应用

javascript - 如何在 HTML 示例中实现 bootstrap-datepicker 沙箱

javascript - 如何在 IE8 中为两个字母的域设置 cookie?

javascript - IE8 : How to set focus to a popup and back without blinking orange