Javascript 错误:“缺少 ) 参数列表”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6882525/
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
Javascript error: "missing ) after argument list"
提问by Ankur
I am getting the error missing ) after argument list
in my Firebug console.
我missing ) after argument list
在 Firebug 控制台中收到错误消息。
I can't understand why. The problem is with the text that is passed in as an argument to the before() method. I am pretty sure it's something to do with the quotation marks. I have tried doing \"
and \'
instead of '
but neither was successful, they gave different errors.
我不明白为什么。问题在于作为参数传入 before() 方法的文本。我很确定这与引号有关。我试图做的\"
和\'
替代'
,但也不是成功的,他们给了不同的错误。
As long as I can add the HTML that is within the before() method I don't mind how I solve this.
只要我可以添加 before() 方法中的 HTML,我不介意我如何解决这个问题。
$(document).ready(
function () {
$("#add").click(
function () {
$("#add").before("<s:text name='queries[0].property' class='small-text' size='28'/><span class='small-text'> = </span>");
});
});
回答by Guffa
There is nothing wrong with the code that you show, so you probably have got some unprintable character in the string that keeps it from working.
您显示的代码没有任何问题,因此您可能在字符串中有一些无法打印的字符,使其无法正常工作。
Try to copy the string and past it back, or if that doesn't fix it, retype the string.
尝试复制字符串并将其粘贴回去,或者如果这不能解决问题,请重新键入字符串。
回答by totallyNotLizards
Looks like you are using jQuery. I'd bet the missing ')' is something to do with your document.ready, looks unbalanced.
看起来您正在使用 jQuery。我敢打赌缺少的 ')' 与您的 document.ready 有关,看起来不平衡。
Try doing it like this:
尝试这样做:
$(function(){
$("#add").click(function(){
$("#add").before("<s:text name='queries[0].property' class='small-text' size='28'/><span class='small-text'> = </span>");
});
});
It's the same as document.ready, just a shortcut but I use it all the time. Think this should be ok.
它与 document.ready 相同,只是一个快捷方式,但我一直在使用它。觉得这个应该没问题。
Hope it helps
希望能帮助到你
EDIT:
编辑:
Oops I missed that string :)
哎呀我错过了那个字符串:)
I'd also try out JK's answer, that looks good to me.
我也会尝试 JK 的答案,这对我来说看起来不错。
回答by Luc125
I think you have to escape some characters, because the HTML parser interprets a </
sequence as the end of a script. So try to use <\/
instead:
我认为您必须转义一些字符,因为 HTML 解析器将</
序列解释为脚本的结尾。所以尝试<\/
改用:
$(document).ready(
function () {
$("#add").click(
function () {
$("#add").before("<s:text name='queries[0].property' class='small-text' size='28'/><span class='small-text'> = <\/span>");
});
});