未捕获的语法错误:意外的标记变量
我有一个错误 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
计算这一行上的左括号:
添加另一个右括号;解析器认为您仍在为
append()
函数指定参数,并且var
关键字在此上下文中无效。另外,请使用分号。如果不是为了你,那就为了道格拉斯的健康吧。
Count the open parentheses on this line:
Add another closing paren; the parser thinks you're still specifying arguments to the
append()
function, and thevar
keyword is invalid in this context.Also, use semicolons. If not for your sake, do it for Douglas' health.
我在控制台中看到了类似的错误消息,其中 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.我遇到了同样的错误,因为我添加了“,”(逗号)而不是“;”(分号)。如果您收到此错误,请仔细重新检查您的代码。
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.
对我来说,问题在于声明变量时的间距。我有一个 JavaScript 脚本,它从我们的数据库动态加载到页面上。我已经复制了脚本并为 sql 数据库创建了一个新条目。虽然我复制了脚本,但复制操作实际上忽略了换行符 (\n),或者 select 语句将所有内容合并到一行中而忽略了换行符 (\n)。我的 JavaScript 看起来像这样:
上面的脚本导致控制台窗口出现错误:
问题出在
var xyz
声明附近的右大括号附近,因为它没有空格,并且它认为这是错误的语法。通过添加一些空格并确保每个语句末尾有分号帮助我解决了问题。工作脚本如下所示: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:
The above script resulted in an error on console window:
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: