参数列表后面的SyntaxError:missing)

时间:2013-09-21 10:06:50

标签: javascript jquery

我收到语法错误:

SyntaxError: missing ) after argument list

从这个jQuery代码:

$('#contentData').append(
  "<div class='media'><div class='media-body'><h4 class='media-heading'>" + 
  v.Name + "</h4><p>" + v.Description + "</p><a class='btn' href='" + 
  type + "'  onclick="(canLaunch('" + v.LibraryItemId + " '))">
  View &raquo;
  </a></div></div>")

哪种错误会产生此Javascript语法错误?

6 个答案:

答案 0 :(得分:27)

你在onclick处理程序中有一个未转义的",用\"转义它

$('#contentData').append("<div class='media'><div class='media-body'><h4 class='media-heading'>" + v.Name + "</h4><p>" + v.Description + "</p><a class='btn' href='" + type + "'  onclick=\"(canLaunch('" + v.LibraryItemId + " '))\">View &raquo;</a></div></div>")

答案 1 :(得分:8)

如何重现此错误:

SyntaxError: missing ) after argument list

此代码产生错误:

<html>
<body>
<script type="text/javascript" src="jquery-2.1.0.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){

  }
</script>
</body>
</html>

如果你运行它并查看firebug中的错误输出,则会出现此错误。传入“就绪”的空函数未关闭。修复如下:

<html>
<body>
<script type="text/javascript" src="jquery-2.1.0.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){

  });      //<-- notice the right parenthesis and semicolon
</script>
</body>
</html>

然后正确解释Javascript。

答案 2 :(得分:4)

对我来说,一旦功能

的拼写错误

例如而不是

$(document).ready(function(){

});

我写了

$(document).ready(funciton(){

});

所以请保持检查

答案 3 :(得分:1)

昨天在以下情况下我遇到了同样的问题。但是我按如下所示修复了它。但是,如果有人可以向我解释为什么此错误在我的情况下特别有用,那就太好了。

运行我的节点文件“ app.js”时在浏览器中显示错误的index.ejs文件的粘贴内容。它的路由“ / blogs”重定向到“ index.ejs”文件。

<%= include partials/header %>
<h1>Index Page</h1>
<% blogs.forEach(function(blog){ %>
    <div>
        <h2><%= blog.title %></h2>
        <image src="<%= blog.image %>">
        <span><%= blog.created %></span>
        <p><%= blog.body %></p>
    </div>
<% }) %>
<%= include partials/footer %>

浏览器出现的错误

SyntaxError:缺少),在编译ejs时,在/home/ubuntu/workspace/RESTful/RESTfulBlogApp/views/index.ejs中的参数列表之后

我如何修复:我在顶部和底部的include语句中删除了“ =“,效果很好。

答案 4 :(得分:1)

在参数列表后

SyntaxError:缺少)。

如果直接不带单引号或双引号的情况下传递字符串,也会出现此问题。

$('#contentData').append("<div class='media'><div class='media-body'><a class='btn' href='" + type + "'  onclick=\"(canLaunch(' + v.LibraryItemName +  '))\">View &raquo;</a></div></div>").

所以请始终保持习惯,如

 onclick=\"(canLaunch(\'' + v.LibraryItemName  + '\'))"\

答案 5 :(得分:-3)

使用:

my_function({width:12});

代替:

my_function(width:12);