如果点击“删除”链接,我想fadeOut
一个div-tag及其嵌套内容。
我写了以下代码:
控制器:
respond_to :html, :js
def destroy_attachment
@div_id = params[:id]
respond_to do |format|
respond_with @div_id
end
end
查看:
<% for attachment in attachments %>
<div class="attachment_<%= attachment.id %>">
.....................
...some other content...
.....................
<%= link_to "Destroy", {controller: "topics" , action: "destroy_attachment"},
:id => attachment.id,:remote => true, :confirm => 'Are you sure?',
:method => :post , class: "icon icon-del" %>
</div>
<% end %>
destroy_attachment.js.erb:
$('.attachment_<%= @div_id %>').fadeOut("slow");
我做错了什么? selectioncall(*.attachment_<%= @div_id %>*)
文件中的.js
是错误的还是别的?
答案 0 :(得分:0)
所以我在我的实现中发现了一些错误,现在它适用于我,使用以下代码:
<强>控制器:强>
def destroy_attachment
@div_id = params[:id]
respond_to do |format|
format.html
format.js
end
end
查看:强>
<%= link_to "Destroy", {controller: "topics" , action: "destroy_attachment",:id => attachment.id}, :remote => true, :confirm => 'Are you sure?', :method => :post , class: "icon icon-del" %>
在这里,我在大括号中移动了“:id =&gt; attachment.id”部分,以便使用Controller中的params方法进行访问
<强> destroy_attachment.js.erb:强>
$("#attachment_<%=@div_id%>").fadeOut(150, function(){
$(this).remove();
});