带有意外令牌的奇怪行为非法错误

Strange behaviour with Unexpected token ILLEGAL Error

本文关键字:非法 错误 意外 令牌      更新时间:2023-09-26

我在Chrome中面临非常奇怪的行为&来自jQuery的Mozilla。我在document.ready函数上得到了非常普遍的Unexpected token ILLEGAL误差。

在使用签名示例时,我在自己的页面上尝试了它。它不能在Mozilla中工作。Chrome,但在IE中工作。然后我删除了signaturepad的所有引用,并在文档中添加了一个简单的警报。准备函数和观察(感谢Chrome JavaScript错误通知)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>

问题已修复。问题是文件保存的编码方式。有问题的文件是用Unicode-1200保存的,而应该用Unicode-65001保存。

感谢所有人的回答/评论。

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

  • 添加一个<!DOCTYPE html>标签到顶部——jquery移动喜欢它
  • 删除<html lang="en">标签前面的缩进
  • 重新下载或尝试使用托管的jquery库(例如从谷歌),看看它是否
  • })之后添加关闭;