【问题标题】:Strange behaviour with Unexpected token ILLEGAL Error意外令牌非法错误的奇怪行为
【发布时间】:2014-07-05 03:13:16
【问题描述】:

我在 jQuery 的 Chrome 和 Mozilla 中遇到了非常奇怪的行为。我的document.ready 函数出现了非常通用的Unexpected token ILLEGAL 错误。

在使用签名板示例时,我在自己的页面上进行了尝试。它不适用于 Mozilla 和 Chrome,但适用于 IE。然后我删除了所有对 signaturepad 的引用,并在 document.ready 函数中放置了一个简单的警报,并观察到(感谢 Chrome JavaScript Errors Notifier)Unexpected token ILLEGAL error is occurring when system try to use jQuery reference。然后我从示例页面 (a.html) 中复制了所有文本,它在此页面 (b.html) 中完美运行,然后再次运行该页面。我很惊讶 a.html 页面工作正常,而 b.html 页面抛出错误。两个页面都在同一个目录中,并且具有相同的内容。

    <html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title> </title>
    <link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css">
    <link href="css/jquery.signaturepad.css"  rel="stylesheet">
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/jquery.mobile-1.3.1.min.js"></script>
</head>
<body>

<script>
    $(document).ready(function () {
        alert('hai');

    })

</script>

</body>
</html>

【问题讨论】:

  • 您是否不小心粘贴了一些非打印字符? (您是否使用会显示非打印字符的编辑器?)
  • 问题可能不在脚本正文中,而是在 jquery.mobile-1.3.1.min.js 中尝试使用 cdn 导入 jquery 并查看是否发生任何更改

标签: javascript jquery html google-chrome signaturepad


【解决方案1】:

问题现已修复。问题在于保存文件的编码。有问题的文件使用 Unicode-1200 保存,而应该使用 Unicode-65001 保存。

感谢大家的回答/cmets。

问候

【讨论】:

    【解决方案2】:

    我会做一些听起来很傻的事情——

    • 在顶部添加一个&lt;!DOCTYPE html&gt; 标签——jquery mobile 喜欢它
    • 去掉&lt;html lang="en"&gt;标签前面的缩进
    • 重新下载或尝试使用托管的 jquery 库(例如来自 google)看看是否是这样
    • }) 之后添加结束;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 2018-07-23
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多