2011-10-14 44 views
5

toggle.js未捕获的SyntaxError:意外的标记非法为Chrome浏览器

var $jq = jQuery.noConflict(); 
$jq(document).ready(function(){ 

    $jq('.isAdd').hide(); 

    $jq("#Add_category").change(function(){   
     var value = $jq("#Add_category option:checked").val(); 
     var theDiv = $jq(".isAdd"); 

     theDiv.slideToggle("slow"); 
    }); 
});​ 

在控制台我:

Uncaught SyntaxError: Unexpected token ILLEGAL

对于Firefox它工作正常,但不适用于Chrome和铬的Ubuntu 。

+0

什么是HTML标记? –

+0

它是:http://pastie.org/2693372 – TiSer

+0

在什么行是错误抛出? –

回答

15

有以下的最后一行的最后});有不可见字符。当我将它粘贴到我的编辑器中时,它显示为.

在编辑器中查看您的代码,该编辑器能够使用某种符号显示不可打印的字符,或者在十六进制编辑器中查看它。

+0

最要感谢的是,迈克尔! – TiSer

+0

谢谢,我复制并粘贴,所以我假设我复制了一个不可见的字符。重写代码后。有效。 – RedRory

+1

如果在代码中使用双引号而不是直线,则也可能会出现此错误。 – awidgery

-1

@TiSer: please check your code for invisible white space chars, on document ready handler is not the problem here, it was the illegal token direct after them – Irishka Oct 14 '11 at 13:57

yeap, it's right! Incredible - one small symbol and all JS code fell. :) – TiSer Oct 17 '11 at 8:50

$ jq(document).ready(...);导致此错误的Chrome

前</body>标签

编辑

您的jQuery脚本移至底部:检查是否有空格

+0

什么?为什么? –

+0

我可以给你一些链接阅读:http://forum.jquery.com/topic/solved-problem-in-chrome-document-ready,http://stackoverflow.com/questions/5596904/jquery-document-ready-problem-with-iron-chrome – Irishka

+0

'意外的标记ILLEGAL'错误是由无效的语法造成的。仅仅使用一个ready处理程序就不能触发这样的错误。 –

0

总结解决问题“意外令牌非法”:

非法手段严格语法错误。

的修复

安装HXD编辑器(推荐),并在其中打开文件。您可以通过检测异常的.(正如它发生在我身上)以及代码的HEX表示法来检测发生错误的位置。保存并替换文件。

相关问题