SCRIPT1014: Invalid character

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

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

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

What is wrong here?

回答1:

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.



回答2:

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.

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

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



回答3:

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.



回答4:

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

` 

character for me in IE11.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!