rails 3 js代码错误

时间:2011-11-01 12:57:52

标签: javascript ruby-on-rails ruby-on-rails-3

我的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

1 个答案:

答案 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它在新行上继续。