Javascript SCRIPT1014:无效字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6261256/
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 20:59:59  来源:igfitidea点击:

SCRIPT1014: Invalid character

javascriptjqueryinternet-explorer

提问by Radu Dragomir

I have this script:

我有这个脚本:

function slideSwitch() {
    var ae = jQuery('#featured-right a.active');
    if ( ae.length == 0 ) {
        ae = jQuery('#featured-right a:first');
        var i = jQuery('#featured-right a').index(ae);
        var bae = jQuery('#featured-left a.fb-'+i);
        bae.show();
    }

    var ne =  ae.next().length ? ae.next() : jQuery('#featured-right a:first');
}

$(document).ready(function(){
    var ae = jQuery('#featured-right a.active');
    if ( ae.length == 0 ) {
        ae = jQuery('#featured-right a:first');
        ae.addClass('active');
        var i = jQuery('#featured-right a').index(ae);
        jQuery('#featured-left a.fb-'+i).show();
        jQuery('#featured-right a:not(.active) span.key').hide();
    }
    setInterval("slideSwitch()", 1000);  
});

which works great on any browser but IE. On IE, IU get

它适用于除 IE 之外的任何浏览器。在 IE 上,IU 得到

SCRIPT1014: Invalid character featured.js, line 1 character 1

What is wrong here?

这里有什么问题?

采纳答案by Radu Dragomir

It seems that IE didn't like the fact that i was accessing the page without a HTTP server :) I was accessing c:\www\my-file. When accessing http://localhost/my-file.. worked great.

IE 似乎不喜欢我在没有 HTTP 服务器的情况下访问页面的事实:) 我正在访问 c:\www\my-file。访问http://localhost/my-file.. 效果很好。

回答by cngodles

I had this same problem. It said there was an error in line 1 row 1 of the main file. I use a ton of AJAX in the page I was using.

我有同样的问题。它说主文件的第 1 行第 1 行有错误。我在我使用的页面中使用了大量的 AJAX。

It all boiled down to the fact that I had onclick="#"on an A tag. Once I removed that, the error went away.

这一切都归结为我在 A 标签上有onclick="#"的事实。一旦我删除了它,错误就消失了。

I think when jQuery loads the html via an AJAX call, it takes the onclick tags and processes the javascript it finds inside.

我认为当 jQuery 通过 AJAX 调用加载 html 时,它会获取 onclick 标签并处理它在里面找到的 javascript。

回答by Mark Rhodes

The problem is likely to be that the file is UTF-8 encoded and the file is being brought in via a script tag which doesn't define this encoding. If you add charset="UTF-8"as an attribute to the importing script tag hopefully that'll fix it.

问题很可能是该文件是 UTF-8 编码的,并且该文件是通过未定义此编码的脚本标记引入的。如果您将charset="UTF-8"一个属性添加到导入脚本标记中,希望能解决它。

回答by Alex W

Watch out for template string literals. This error was caused by a

注意模板字符串文字。这个错误是由一个

`

character for me in IE11.

我在 IE11 中的角色。