意外的标识符错误jQuery

Unexpected identifier error jQuery

本文关键字:jQuery 错误 标识符 意外      更新时间:2023-09-26

我在jQuery中的一行代码有问题。我已经解决了Unaught SyntaxError:UnExpected String。现在我得到另一个错误

Uncaught SyntaxError: UnExpected Identifier

对于这行代码:

row += '<input type='text' name='fname' value="" class='fedit' />'n';

我已经通读了一些其他的答案,但我没能解决我的问题。

您应该转义引号。发生的情况是,一旦您添加了',编译器就会认为您的字符串已经结束,以避免使用'(如'')对您的字符串进行转义。这允许您键入'Foo''s Bar'

代码

row += '<input type=''text'' name=''fname'' value="" class=''fedit'' />'n';

详细信息编译器看到的几个部分

字符串:'<input type='

代码:text

字符串:'name='

代码:fname

字符串:'value="" class='

代码:fedit

字符串:'/>'n'

换行符'n是不必要的,因为HTML字符串不需要它们,您可能需要放一个<br/>

尝试row += "<input type='text' name='fname' value='' class='fedit' />'n";
您正在混合单引号和多引号

尝试row += '<input type="text" name="fname" value="" class="fedit" />'n';

报价与冲突