jQuery SyntaxError:意外令牌= [英] jQuery SyntaxError: Unexpected token =
本文介绍了jQuery SyntaxError:意外令牌=的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将一堆变量传递给一个隐藏的输入值,但此代码中出现了一个愚蠢的语法错误:
I am trying to pass a bunch of variables to a hidden input value but I am getting a stupid syntax error in this code:
$('#imgdata').append(
'<input type="hidden" name="imgdata[' + id + '][width]" value="' + _width + '"/>
<input type="hidden" name="imgdata[' + id + '][height]" value="' + _height + '" />
<input type="hidden" name="imgdata[' + id + '][left]" value="' + _left + '" />
<input type="hidden" name="imgdata[' + id + '][top]" value="' + _top + '" />
<input type="hidden" name="imgdata[' + id + '][src]" value="' + _src + '" />'
);
我必须忽略一个简单的语法错误.控制台在第三行告诉我.
I must be overlooking a simple syntax mistake. Console tells me its in 3rd line.
解决方案:
问题在于换行.使代码内联而不用按Enter键即可对其进行格式设置.
The issue was with the line-wrapping. Making the code inline without pressing enter for formatting fixed it.
推荐答案
JavaScript字符串行必须以\
结尾.
除此之外,请确保所有变量均已定义.
JavaScript string lines must be end with \
.
Besides that make sure all the variables are indeed defined.
您的代码示例应如下:
$('#imgdata').append(
'<input type="hidden" name="imgdata[' + id + '][width]" value="' + _width + '"/>\
<input type="hidden" name="imgdata[' + id + '][height]" value="' + _height + '" />\
<input type="hidden" name="imgdata[' + id + '][left]" value="' + _left + '" />\
<input type="hidden" name="imgdata[' + id + '][top]" value="' + _top + '" />\
<input type="hidden" name="imgdata[' + id + '][src]" value="' + _src + '" />'
);
这篇关于jQuery SyntaxError:意外令牌=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文