我的process_form.js.erb
文件中包含此代码:
$('#write_offs_table > tbody').append('<tr class="list-line-<%= cycle('even', 'odd') %>" id="<%= @write_off.id %>">
<td class="name"><%= @write_off.date %></td>
<td><%= @write_off.user.name %></td>
<td><%= @write_off.status %></td>
</tr>');
它没有执行,chrome显示错误:
未捕获的SyntaxError:意外的标记ILLEGAL
答案 0 :(得分:1)
试试这个:
$('#write_offs_table > tbody').append('<tr class=list-line-<%= cycle("even", "odd") %> id="<%= @write_off.id %>">\
<td class="name"><%= @write_off.date %></td>\
<td><%= @write_off.user.name %></td>\
<td><%= @write_off.status %></td>\
</tr>');
我使用\
字符告诉javascript它在新行上继续。