简体   繁体   中英

rails 3 js code error

I have this code in my process_form.js.erb file:

$('#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>');

it doesn't execute and chrome shows me an error:

Uncaught SyntaxError: Unexpected token ILLEGAL

Try this:

$('#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>');

I used the \\ character to tell javascript that it continues on a new line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM