jQuery 语法错误:缺少 ) 参数列表后

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18931344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:47:31  来源:igfitidea点击:

SyntaxError: missing ) after argument list

javascriptjquery

提问by karthik

I am getting the syntax error:

我收到语法错误:

SyntaxError: missing ) after argument list

From this jQuery code:

从这个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>")

What kinds of mistakes produce this Javascript Syntax error?

什么样的错误会产生这个 Javascript 语法错误?

回答by Arun P Johny

You had a unescaped "in the onclick handler, escape it with \"

"在 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>")

回答by Eric Leschinski

How to reproduce this error:

如何重现此错误:

SyntaxError: missing ) after argument list

This code produces the error:

此代码产生错误:

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

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

If you run this and look at the error output in firebug, you get this error. The empty function passed into 'ready' is not closed. Fix it like this:

如果您运行此程序并查看 firebug 中的错误输出,则会收到此错误。传递给 'ready' 的空函数没有关闭。像这样修复它:

<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>

And then the Javascript is interpreted correctly.

然后 Javascript 被正确解释。

回答by Chaitanya Gadkari

For me, once there was a mistake in spelling of function

对我来说,曾经有一次函数拼写错误

For e.g. instead of

例如代替

$(document).ready(function(){

});

I wrote

我写

$(document).ready(funciton(){

});

So keep that also in check

所以也要检查一下

回答by utkarsh-k

I faced the same issue in below scenario yesterday. However I fixed it as shown below. But it would be great if someone can explain me as to why this error was coming specifically in my case.

我昨天在下面的场景中遇到了同样的问题。但是我修复了它,如下所示。但是,如果有人能向我解释为什么在我的情况下会出现此错误,那就太好了。

pasted content of index.ejs file that gave the error in the browser when I run my node file "app.js". It has a route "/blogs" that redirects to "index.ejs" file.

当我运行我的节点文件“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 %>

The error that came on the browser:

浏览器上出现的错误

SyntaxError: missing ) after argument list in /home/ubuntu/workspace/RESTful/RESTfulBlogApp/views/index.ejs while compiling ejs

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

How I fixed it: I removed "=" in the include statements at the top and the bottom and it worked fine.

我是如何修复它的:我在顶部和底部的包含语句中删除了“=”,它运行良好。

回答by rinku Choudhary

SyntaxError: missing ) after argument list.

SyntaxError: missing ) 在参数列表之后。

the issue also may occur if you pass string directly without a single or double quote.

如果您直接传递字符串而没有单引号或双引号,也可能会出现此问题。

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

so always keep the habit to pass in a quote like

所以总是保持传递这样的引用的习惯

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

回答by T.Todua

use:

用:

my_function({width:12});

Instead of:

代替:

my_function(width:12);