Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.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
Javascript多行字符串和意外标记非法_Javascript_String_Templates_Underscore.js_Multiline - Fatal编程技术网

Javascript多行字符串和意外标记非法

Javascript多行字符串和意外标记非法,javascript,string,templates,underscore.js,multiline,Javascript,String,Templates,Underscore.js,Multiline,我在自己的单独js文件中有一个多行字符串模板,用于下划线js。然而,无论我如何逃脱换行符,我仍然会得到: 未捕获的语法错误:意外标记非法 当文件加载到浏览器中时,位于文件的第1行 App.Templates['template1'] = '\ <div data-role="page" data-theme="c" id="" data-title="">\ <div data-role="content" class="subnav">\

我在自己的单独js文件中有一个多行字符串模板,用于下划线js。然而,无论我如何逃脱换行符,我仍然会得到:

未捕获的语法错误:意外标记非法

当文件加载到浏览器中时,位于文件的第1行

App.Templates['template1'] = '\

<div data-role="page" data-theme="c" id="" data-title="">\

    <div data-role="content" class="subnav">\

        <table id="day-table" cellpadding="0" cellspacing="0" border="0">\
            <thead class="ui-body-a">\
                <tr>\
                    <th>T</th>\
                    <th>J</th>\
                    <th>H</th>\
                    <th>C</th>\
                </tr>\
            </thead>\
            <tbody>\
            </tbody>\
            <tfoot>\
                <tr>\
                    <td class="total-label" colspan="2">Total:</td>\
                    <td class="total"></td>\
                </tr>\
                <tr>\
                    <td class="btn-row">\
                        <a href="#r" data-role="button" id="add-btn" data-rel="dialog" data-mini="true" data-inline="true" data-icon="add">Add Rows</a>\
                        <a href="#" data-role="button" id="save-btn" data-rel="dialog" data-mini="true" data-inline="true" data-theme="b" data-icon="check">Save</a>\
                    </td>\
                </tr>\
            </tfoot>\
        </table>\

    </div><!--/content-->\

</div><!-- /page -->';
App.Templates['template1']='\
\
\
\
\
\
T\
J\
H\
C\
\
\
\
\
\
\
总数:\
\
\
\
\
\
\
\
\
\
\
\
';

有什么想法吗?

字符串中不允许使用行终止符,您需要对其进行转义:

App.Templates['template1'] = '\
\
<div data-role="page" data-theme="c" id="" data-title="">\
\
    <div data-role="content" class="subnav">\
\
        <table id="day-table" cellpadding="0" cellspacing="0" border="0">\
            <thead class="ui-body-a">\
                <tr>\
                    <th>T</th>\
                    <th>J</th>\
                    <th>H</th>\
                    <th>C</th>\
                </tr>\
            </thead>\
            <tbody>\
            </tbody>\
            <tfoot>\
                <tr>\
                    <td class="total-label" colspan="2">Total:</td>\
                    <td class="total"></td>\
                </tr>\
                <tr>\
                    <td class="btn-row">\
                        <a href="#r" data-role="button" id="add-btn" data-rel="dialog" data-mini="true" data-inline="true" data-icon="add">Add Rows</a>\
                        <a href="#" data-role="button" id="save-btn" data-rel="dialog" data-mini="true" data-inline="true" data-theme="b" data-icon="check">Save</a>\
                    </td>\
                </tr>\
            </tfoot>\
        </table>\
\
    </div><!--/content-->\
\
</div><!-- /page -->';
App.Templates['template1']='\
\
\
\
\
\
\
\
\
T\
J\
H\
C\
\
\
\
\
\
\
总数:\
\
\
\
\
\
\
\
\
\
\
\
\
\
';
为了更容易看到行终止符所在的位置,可以在文本编辑器中打开可见的空白,您应该看到如下内容:


我想出来了。空行也需要转义

App.Templates['template1'] = '\
\
<div data-role="page" data-theme="c" id="" data-title="">\
\
    <div data-role="content" class="subnav">\
\
        <table id="day-table" cellpadding="0" cellspacing="0" border="0">\
            <thead class="ui-body-a">\
                <tr>\
                    <th>T</th>\
                    <th>J</th>\
                    <th>H</th>\
                    <th>C</th>\
                </tr>\
            </thead>\
            <tbody>\
            </tbody>\
            <tfoot>\
                <tr>\
                    <td class="total-label" colspan="2">Total:</td>\
                    <td class="total"></td>\
                </tr>\
                <tr>\
                    <td class="btn-row">\
                        <a href="#r" data-role="button" id="add-btn" data-rel="dialog" data-mini="true" data-inline="true" data-icon="add">Add Rows</a>\
                        <a href="#" data-role="button" id="save-btn" data-rel="dialog" data-mini="true" data-inline="true" data-theme="b" data-icon="check">Save</a>\
                    </td>\
                </tr>\
            </tfoot>\
        </table>\
\
    </div><!--/content-->\
\
</div><!-- /page -->';
App.Templates['template1']='\
\
\
\
\
\
\
\
\
T\
J\
H\
C\
\
\
\
\
\
\
总数:\
\
\
\
\
\
\
\
\
\
\
\
\
\
';

你错过了不少```我喜欢Javascript,但有时它让我想哭个不停。谢谢你的回答。即使我经过一点尝试和错误才找到答案,我还是会接受你的答案。@XMO需要理解的重要一点是,你正在逃避“看不见的”换行符。。。“空”行中仍有换行符。您可以在文本编辑器中打开可见的新行,并查看它们需要转义的位置。我必须找出如何在SublimiteText中进行转义。谢谢是的,它实际上只是一个必须转义的换行符——具体行上的内容无关紧要。