微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Javascript多行字符串和意外令牌ILLEGAL

我有一个多行字符串模板,它自己的独立的js文件用于下划线js.然而,无论我如何逃脱换行,我还是得到一个

Uncaught SyntaxError: Unexpected token ILLEgal

文件加载到浏览器中时,该文件的第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'] = '\
\
<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 -->';

为了更容易地看到你有线终结者的位置,你可以在你的文本编辑器中打开可见的空格,你应该看到这样的东西:

原文地址:https://www.jb51.cc/js/152524.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐