0

我编写了一些 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>


所以,

  • 是什么导致了这个错误?
  • 我该如何解决?
4

1 回答 1

2

去掉分号并将其放在引号中(宽度属性值):

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

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

URL:“意外令牌非法”没有明显原因

于 2015-09-05T23:25:42.503 回答