我有一个多行字符串模板,它自己的独立的js文件用于下划线js.然而,无论我如何逃脱换行,我还是得到一个:
Uncaught @R_502_156@Error: Unexpected token ILLEGAL
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 -->';
为了更容易地看到你有线终结者的位置,你可以在你的文本编辑器中打开可见的空格,你应该看到这样的东西: