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

发布于 2024-10-09 13:25:36 字数 796 浏览 6 评论 0原文

我有一个错误 Uncaught SyntaxError: Unexpected token var displayed between (1) and (2) 这是一个非常奇怪的错误,而且根本没有意义。

if ($hiddenimage.length==0) { //if this is the first time moving over or clicking on the anchor link
    var $hiddenimage=$('<img src="'+this.href+'" />').appendTo($hiddenimagediv) //populate hidden div with enlarged image
    $hiddenimage.bind('loadevt', function(e){ //when enlarged image has fully loaded
        loadarea.empty().append($.thumbnailviewer2.buildimage($, $anchor, s, options)
        (1) - var $targetimage=$.thumbnailviewer2.buildimage($, $anchor, s, options) //create reference actual enlarged image
        (2) - $loadarea.empty().append($targetimage) //show enlarged image
        $.thumbnailviewer2.showimage($targetimage, s)
    })

I have an error Uncaught SyntaxError: Unexpected token var displayed between (1) and (2) its a very odd error and it doesn't make sense at all.

if ($hiddenimage.length==0) { //if this is the first time moving over or clicking on the anchor link
    var $hiddenimage=$('<img src="'+this.href+'" />').appendTo($hiddenimagediv) //populate hidden div with enlarged image
    $hiddenimage.bind('loadevt', function(e){ //when enlarged image has fully loaded
        loadarea.empty().append($.thumbnailviewer2.buildimage($, $anchor, s, options)
        (1) - var $targetimage=$.thumbnailviewer2.buildimage($, $anchor, s, options) //create reference actual enlarged image
        (2) - $loadarea.empty().append($targetimage) //show enlarged image
        $.thumbnailviewer2.showimage($targetimage, s)
    })

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

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

发布评论

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

评论(4

初见你 2024-10-16 13:25:36

计算这一行上的左括号:

loadarea.empty( ).append($.thumbnailviewer2.buildimage($, $anchor, s, options)
              ^ ^       ^                             ^                      ^
              1 0       1                             2                      1

添加另一个右括号;解析器认为您仍在为 append() 函数指定参数,并且 var 关键字在此上下文中无效。

另外,请使用分号。如果不是为了你,那就为了道格拉斯的健康吧。

Count the open parentheses on this line:

loadarea.empty( ).append($.thumbnailviewer2.buildimage($, $anchor, s, options)
              ^ ^       ^                             ^                      ^
              1 0       1                             2                      1

Add another closing paren; the parser thinks you're still specifying arguments to the append() function, and the var keyword is invalid in this context.

Also, use semicolons. If not for your sake, do it for Douglas' health.

趁微风不噪 2024-10-16 13:25:36

我在控制台中看到了类似的错误消息,其中 minifier 正在解析我的 javascript 源代码。我发现像这样使用 // comments 总是会中断缩小过程,并在控制台中给我一个错误。因此,我像这样切换了所有/* comments */MDN Javascript 评论 并立即按预期解析所有内容。希望有帮助。

I had a similar error message in the console with the minifier parsing my javascript source code. I found that using // comments like so always interrupted the minification process, and gave me an error in the console. Therefore i switched all /* comments */ like so. MDN Javascript Comments And immediately everything parsed as expected. Hope it helps.

青衫儰鉨ミ守葔 2024-10-16 13:25:36

我遇到了同样的错误,因为我添加了“,”(逗号)而不是“;”(分号)。如果您收到此错误,请仔细重新检查您的代码。

I got the same error because I have added ','(comma) instead of ';'(semi-colon). IF you get this error, please re-check your code carefully.

甜嗑 2024-10-16 13:25:36

对我来说,问题在于声明变量时的间距。我有一个 JavaScript 脚本,它从我们的数据库动态加载到页面上。我已经复制了脚本并为 sql 数据库创建了一个新条目。虽然我复制了脚本,但复制操作实际上忽略了换行符 (\n),或者 select 语句将所有内容合并到一行中而忽略了换行符 (\n)。我的 JavaScript 看起来像这样:

window.onload = function(){ var abc = 'xyz';}var xyz = 'abc';

上面的脚本导致控制台窗口出现错误:

Uncaught SyntaxError: Unexpected token 'var'

问题出在 var xyz 声明附近的右大括号附近,因为它没有空格,并且它认为这是错误的语法。通过添加一些空格并确保每个语句末尾有分号帮助我解决了问题。工作脚本如下所示:

window.onload = function(){ var abc = 'xyz';}; var xyz = 'abc';

For me, the problem was spacing when declaring variables. I had a javascript script that was getting loaded from our db dynamically on the page. I had copied the script and create a new entry for sql database. While, I copied the script, the copy action actually ignored the newlines (\n) or the select statement gave everything merged in a single line ignoring the newlines(\n). My javascript looked like this:

window.onload = function(){ var abc = 'xyz';}var xyz = 'abc';

The above script resulted in an error on console window:

Uncaught SyntaxError: Unexpected token 'var'

The problem was near the closing curly brace near var xyz declaration as it has no space and it considers it as a wrong syntax. By adding some space and making sure there is semicolon at the end of each statement helped me clear the issues. Working script looked like this:

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