未捕获的语法错误:Chrome 浏览器的意外标记非法

发布于 2024-12-09 19:20:56 字数 483 浏览 0 评论 0原文

toggle.js

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");
    });
});​

在控制台中我有:

未捕获的语法错误:意外的标记非法

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

toggle.js

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");
    });
});​

In console I had:

Uncaught SyntaxError: Unexpected token ILLEGAL

For Firefox it's works fine, but not for Chrome and Chromium for Ubuntu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

箹锭⒈辈孓 2024-12-16 19:20:56

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

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

There is an invisible character following the last }); of your last line. When I pasted it into my editor, it appeared as a ..

View your code in an editor capable of displaying non-printable characters with some kind of symbol, or view it in a hex editor.

ま柒月 2024-12-16 19:20:56

总结一下“Unexpected Token ILLEGAL”问题的解决方案:

ILLEGAL 严格意味着语法错误。

修复

安装 HxD 编辑器(推荐)并在其中打开文件。您可以通过使用代码的十六进制表示检测异常的 . (正如我所发生的那样)来检测错误到底发生在哪里。保存并替换文件。

To summarize the solution to problem with "Unexpected Token ILLEGAL":

ILLEGAL means strictly Syntax Error.

The Fix

Install HxD Editor (recommended) and open your file in it. You can detect where exactly the error is occuring by detecting unusual . (as it happened with me), with the code's HEX representation. Save and replace the file.

望她远 2024-12-16 19:20:56

@TiSer:请检查您的代码中是否存在不可见的空白字符,
文档就绪处理程序不是这里的问题,而是非法的
紧随其后的令牌 – Irishka 2011 年 10 月 14 日 13:57

是的,没错!难以置信——一个小符号和所有 JS 代码都掉了。
:) – TiSer 2011 年 10 月 17 日 8:50

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

将您的 jQuery 脚本移至底部之前 << /身体>标签

编辑:检查空格

@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(...); is causing this error Chrome

move your jQuery script to the bottom before < /body > tag

EDIT: check for white spaces

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文