2011-07-26 51 views
0

如何在多行上做到這一點。我試過了,但它不起作用。格式化jquery js.erb問題

$('#wall-top').after("<div id='buttons' style='display: block;'><%=escape_javascript(link_to (image_tag 'btn-post-greeting.png', :width => '241', :height => '68', :alt => 'Btn Post Greeting', :id => 'BtnBoxGreeting'), new_greeting_path, :remote => true) %><%=escape_javascript(link_to (image_tag 'btn-invite-friends.png', :width => '245', :height => '68', :alt => 'Invite Friends', :id => 'BtnBoxFriends'), new_greeting_path, :remote => true, :style => 'display: block;') %></div>"); 

回答

1

拉ERB豆腐塊分成不同的JavaScript變量,格式化ERB任何你想要的,然後這一切在JavaScript土地粘貼在一起。也許是這樣的:

var greet = '<%=escape_javascript(
    link_to(
     image_tag('btn-post-greeting.png', 
      :width => '241', 
      :height => '68', 
      :alt => 'Btn Post Greeting', 
      :id  => 'BtnBoxGreeting' 
     ) 
    ), 
    new_greeting_path, 
    :remote => true 
) %>'; 
var invite = '<%=escape_javascript(
    link_to(
     image_tag('btn-invite-friends.png', 
      :width => '245', 
      :height => '68', 
      :alt => 'Invite Friends', 
      :id  => 'BtnBoxFriends' 
     ) 
    ), 
    new_greeting_path, 
    :remote => true, 
    :style => 'display: block;' 
) %>'; 

$('#wall-top').after(
     '<div id="buttons" style="display: block;">' 
    + greet 
    + invite 
    + '</div>' 
); 

這應該讓你開始。我會更進一步並將style屬性移動到您的樣式表中;這將減少噪音,並給你一個更清晰的問題分離。

+0

你是一個搖滾的開始。非常感謝soooo – chell