Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery语法错误:意外标记=_Jquery - Fatal编程技术网

jQuery语法错误:意外标记=

jQuery语法错误:意外标记=,jquery,Jquery,我试图将一组变量传递给一个隐藏的输入值,但我在这段代码中遇到了一个愚蠢的语法错误: $('#imgdata').append( '<input type="hidden" name="imgdata[' + id + '][width]" value="' + _width + '"/> <input type="hidden" name="imgdata[' + id + '][height]" value="' + _height + '" /&g

我试图将一组变量传递给一个隐藏的输入值,但我在这段代码中遇到了一个愚蠢的语法错误:

$('#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 + '"  />'
 );
$('imgdata')。附加(
'
'
);
我一定忽略了一个简单的语法错误。控制台告诉我它在第三行

解决方案:


问题在于包装线。将代码内联而不按enter键进行格式化已修复。

JavaScript字符串行必须以
\
结尾。 除此之外,确保所有变量都已定义

您的代码示例应如下所示:

$('#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 + '"  />'
 );​
$('imgdata')。附加(
'\
\
\
\
'
);​

想用控制台告诉您的内容来启发我们吗?它只是“语法错误”,完全没有其他信息吗?我猜“Unterminated String Literal”这个词可能在那里的某个地方无论哪种方式,你都可以考虑通过确保每行以<代码> +<代码>开始,然后开始3,4,5,并不是每个编辑器都能无缝地处理换行。Chrome在第3行中说了
未捕获的SyntaxError:Unexpected token=
,而safari说了
SyntaxError:Unexpected EOF
这个问题确实是换行问题。我只是在文本编辑器中做了一行,这就解决了它。非常感谢。