我不断收到未终止的字符串文字错误
I keep getting a unterminated string literal error
它一直给我一个未终止的字符串文字错误,但我看不到问题。如何在下面修复它:
var $fileImage = $("<form action='upload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startUpload();' >
<p class='f1_upload_process'>Loading...<br/><img src='Images/loader.gif' /><br/></p><p class='f1_upload_form'><br/><label>
File: <input name='fileImage' type='file' class='fileImage' /></label><label><input type='submit' name='submitBtn' class='sbtn' value='Upload' /></label>
</p> <iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'></iframe></form>");
$image.append($fileImage);
JavaScript 不是 PHP。字符串中不允许使用换行符。
在每行末尾添加 '
,或使用 " + "
连接字符串。
// Using ', scroll to the right to see how to use it
var $fileImage = $("<form action='upload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startUpload();' >'
<p class='f1_upload_process'>Loading...<br/><img src='Images/loader.gif' /><br/></p><p class='f1_upload_form'><br/><label>'
File: <input name='fileImage' type='file' class='fileImage' /></label><label><input type='submit' name='submitBtn' class='sbtn' value='Upload' /></label>'
</p> <iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'></iframe></form>");
// Using string concatenation
var $fileImage = $("<form action='upload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startUpload();' >" +
"<p class='f1_upload_process'>Loading...<br/><img src='Images/loader.gif' /><br/></p><p class='f1_upload_form'><br/><label>" +
"File: <input name='fileImage' type='file' class='fileImage' /></label><label><input type='submit' name='submitBtn' class='sbtn' value='Upload' /></label>" +
"</p> <iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'></iframe></form>");
由于您使用的是jQuery,因此我建议使用jQuery创建可读且可维护的代码:
var $form = $('<form>', {
action: 'upload.php',
method: 'post',
enctype: 'multipart/form-data',
target: 'upload_target'
}).submit(startUpload);
// Et cetera.
相关文章:
- JavaScript 中数据库数据的未终止字符串文字
- 错误:JSON分析错误:使用角度转换时,属性名称必须是字符串文字
- 使用鸭子类型的对象键入字符串文字
- iMacros Firefox错误:“;未终止的字符串文字“;
- 为什么我得到“;非法字符语法错误未终止的字符串文字“;当我使用javascript时
- 谷歌闭包编译器如何处理引号(字符串文字)
- JavaScript 中未终止的字符串文字
- 换行符导致 JavaScript 中的错误“未终止字符串文字”
- 使用 Rhino 更改 JavaScript 字符串文字
- 铬 - 意外令牌 非法.火狐和.字符串文字
- 未终止的字符串文字 - Javascript
- 如何解决此字符串文字错误
- Vim将内容行转换为JavaScript字符串文字
- PHP 包含未终止的字符串文字消息
- JS未终止的字符串文字文档写入
- 字符转义:从 Python 字符串文字到 JSON,然后到 HTML
- 我不断收到未终止的字符串文字错误
- Javascript Regexp和“;字符串文字“;
- SyntaxError:未终止的字符串文字
- 为什么这个表达式在条件中返回实际的字符串文字