Javascript 与 IE8 - 预期的标识符、字符串或数字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5584249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:55:16  来源:igfitidea点击:

Javascript vs. IE8 - Expected identifier, string or number

javascriptjquerydebugginginternet-explorer-8

提问by jondavidjohn

No, it's not an extra comma.

不,这不是一个额外的逗号。

Here is the snip that is giving me the problem.

这是给我带来问题的剪辑。

$(document).ready(function(){   
    $("div#slider").easySlider({
        auto: false,
        continuous: true,
        nextId: "nextBtn",
        prevId: "prevBtn"
    });

    $("div#slider-banner").easySlider({
        auto: true,
        continuous: true,
        controlsShow: false
    });
        // <---------------------------------- Line 14
    $("div#slider-photos").easySlider({
        auto: true,
        continuous: true,
        controlsShow: false
    });

    $("#marquee").marquee({
        scrollSpeed: 25,
        pauseSpeed: 2000,
        showSpeed: 850

    }); 
});

ERROR DETAILS

错误详情

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; Tablet PC 2.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
Timestamp: Wed, 6 Apr 2011 15:20:42 UTC


Message: Expected identifier, string or number
Line: 14
Char: 5
Code: 0

This is happening on random IE8 installs, any ideas?

这是在随机安装 IE8 时发生的,有什么想法吗?

回答by AsGoodAsItGets

Try putting all your object properties in (double)quotes, like this:

尝试将所有对象属性放在(双)引号中,如下所示:

$("div#slider").easySlider({
    'auto': false,
    'continuous': true,
    'nextId': "nextBtn",
    'prevId': "prevBtn"
});

回答by dev101

In 2015. if you still care about IE8 compatibility (more or less), my issue with this error was only manifesting on a live server, but didn't happen on localhost (go figure). And, it triggered IE8 error in such a way that it went down into IE7 Compatibility View, which also sucks just the same as Quirks Mode.

在 2015 年。如果你仍然关心 IE8 兼容性(或多或少),我的这个错误问题只出现在实时服务器上,但没有发生在本地主机上(去图)。而且,它以这样一种方式触发了 IE8 错误,以至于它进入了 IE7 兼容性视图,这也与 Quirks 模式一样糟糕。

In any case, the problem could not be solved by any of the above tips, and the issue was a trailing comma after listing some parameters/options.

无论如何,上述任何提示都无法解决问题,问题是列出了一些参数/选项后的尾随逗号。

For Example:

例如:

$(document).ready(function(){
    $('#selector').func({
        rules: {
            parameter1: {
                option1: true,
                option2: 1,
                option3: 5
            }
        }, // <- this trailing comma is fatal to IE8
    });
});

回答by William

I had similar issue with knockout class attr binding. It happened that the class attribute had to be enclosed in quotes like 'class'.

我在淘汰赛类 attr 绑定方面遇到了类似的问题。碰巧 class 属性必须用引号括起来,如“class”。