JavaScript:在参数列表之后缺少 )

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1865928/
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-22 21:40:48  来源:igfitidea点击:

JavaScript: missing ) after argument list

javascriptjqueryajax

提问by Lea

This javascript produces an error:

这个 javascript 产生一个错误:

missing ) after argument list

缺少 ) 在参数列表之后

In firebug with the code:

在带有代码的萤火虫中:

<script type=\"text/javascript\">
function add( answer )
{   
  $.post('../page.php?cmd=view&id=3523', 
    {user_id: 3523, other_user_id: 2343}, function(d)
      $(answer).after(\"<span>Done!</span>\").remove();
    });
  }
}
</script>

What am I doing wrong?

我究竟做错了什么?

回答by dxh

function dmisses an opening bracket, {

函数d缺少一个左括号,{

$(answer).after(should not be escaped \", just a regular quote will do "

$(answer).after(不应该被转义\",只是一个普通的报价就可以了"

回答by Kuroki Kaze

Close post()function. third string from bottom should be ), not }.

关闭post()功能。倒数第三个字符串应该是),不是}

EDIT: sorry, should be like this:

编辑:对不起,应该是这样的:

<script type=\"text/javascript\">
function add( answer )
{   
    $.post('../page.php?cmd=view&id=3523', {user_id: 3523, other_user_id: 2343}, function(d) {
        $(answer).after(\"<span>Done!</span>\").remove();
    });
}

回答by yoda

Why are you escaping quotes? The problem is here :

你为什么要转义引号?问题在这里:

$(answer).after(\"<span>Done!</span>\").remove();

change to

改成

$(answer).after("<span>Done!</span>").remove();

or

或者

$(answer).after('<span>Done!</span>').remove();

Also, you're missing a { after the post() function (probably you missed the right spot, since there's another in the wrong place), so the final output :

此外,您在 post() 函数之后缺少 { (可能您错过了正确的位置,因为在错误的位置还有另一个),因此最终输出:

<script type=\"text/javascript\">
function add( answer )
{   
$.post('../page.php?cmd=view&id=3523', {user_id: 3523, other_user_id: 2343}, function(d) {
            $(answer).after("<span>Done!</span>").remove();
        });
}
</script>

回答by markmywords

function add( answer )
{   
$.post('../page.php?cmd=view&id=3523', 
       {user_id: 3523, other_user_id: 2343}, 
       function(d){
         $(answer).after("<span>Done!</span>").remove()
       });
};