如何修复JavaScript语法错误:无效或意外的令牌错误?

如何修复JavaScript语法错误:无效或意外的令牌错误?,javascript,jquery,Javascript,Jquery,我的JavaScript文件中有以下代码: input = '<input id="ytRequirementsForm_additional_f__12" type="hidden" value="" name="RequirementsForm[additional][f__12][]" /> <input class="form-control" name="RequirementsForm[additional][f__12][]" id="Requirem

我的JavaScript文件中有以下代码:

  input = '<input id="ytRequirementsForm_additional_f__12" type="hidden" value="" name="RequirementsForm[additional][f__12][]" />
    <input class="form-control" name="RequirementsForm[additional][f__12][]" id="RequirementsForm_additional_f__12" type="file" />
<div class="RequirementsForm_additional_f__12 fileprogress" style="display: none"><div class="filename">
                <span class="glyphicon glyphicon-paperclip" aria-hidden="true"></span>
                <strong></strong>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
            </div>
            <div class="progress">
                <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="1"
                     aria-valuemin="0" aria-valuemax="100">
                    <span class="percent">0</span>%
                         </div>
            </div>
            <div class="info_danger_text"><p></p></div>
        </div>
        ';
input=”

×
0%

';

但是,当我运行web应用程序时,它显示未捕获的
SyntaxError:Invalid或unexpected token
错误。如何修复它?

您只能在ES6中使用多行字符串。为此,您必须使用反勾号字符而不是引号


请参见

您应该只在一行中声明字符串变量。如果要在多行中写入,可以通过以下方式完成:

  • 将每一行与+
    input=''+
    '' +
    
    '';我看到您的“字符串”中有换行符。在JavaScript中,如果要将字符串分配给包含换行符的变量,应在行尾使用“
    \
    ”。 以下是更正的代码

    input = '<input id="ytRequirementsForm_additional_f__12" type="hidden" value="" name="RequirementsForm[additional][f__12][]" />\
    <input class="form-control" name="RequirementsForm[additional][f__12][]" id="RequirementsForm_additional_f__12" type="file" />\
    <div class="RequirementsForm_additional_f__12 fileprogress" style="display: none">'
    
    input=”\
    \
    '
    

    我希望它能帮助您:)

    看起来像是字符串末尾缺少了一个
    结尾缺少了一些东西可能是
    ?在JS中不能这样做多行字符串。使用模板字符串或转义换行符。