如何在多行上进行此操作。我试过了,但它不起作用。
$('#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>");
答案 0 :(得分: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
属性移动到你的样式表中;这将减少噪音,让你更清晰地分离问题。