gpt4 book ai didi

javascript - 如何解决JavaScript 'Unxpected Token Error'?

转载 作者:行者123 更新时间:2023-12-02 15:43:25 25 4
gpt4 key购买 nike

我编写了一些 JavaScript 代码,运行时会产生以下错误:

"error"
"SyntaxError: Unexpected token ILLEGAL

我不知道这个错误是什么意思。我尝试用谷歌搜索,但找不到任何有用的东西。

这是我的代码:

<小时/>

HTML:

$(document).ready(function(){
$('#fostering').on('click', function(){
$(this).animate({
width : 50px;
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<title> Something </title>
</head>
<body>
<div id="fostering"></div>
</body>
</html>

<小时/>

所以,

  • 导致此错误的原因是什么?
  • 如何解决?

最佳答案

删除分号并将其放在引号中(width 属性值):

  $('#fostering').on('click', function(){
$(this).animate({
width : "50px"
});
});

当 Angular 色出现在不该出现的位置时,就会出现此错误。基本上,如果您想了解有关 JS 如何解析给定代码的更多信息,那么这里有一篇关于它的好文章,

网址:No visible cause for "Unexpected token ILLEGAL"

关于javascript - 如何解决JavaScript 'Unxpected Token Error'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32418579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com