这是用于待办事项列表的复选框。
在我使用之前
<%= link_to "Finished!", finish_task_path(feed_item), :method=>:put,:remote=>true%>
与finish.js中的一段JavaScript
$('#task_<%= @task.id %>.task').fadeOut();
现在,而不是使用
link_to
我想用
check_box_tag
因此,每次用户单击复选框时,都应使该条目淡出
我试过了
<%= check_box_tag 'finish[]',feed_item.id,false,:onchange => remote_function(:url=>finish_task_path(feed_item),:method=>:put, :before => "$('#task_#{feed_item.id}').show();", :complete => "$('#task_#{feed_item.id}').hide(); ") %>
但它不起作用,我也不知道该如何使用
:with =>
这里。
先感谢您。
最佳答案
您正在使用jQuery。这意味着您应该使用UJS。因此,请从代码中删除所有这些内联JavaScript调用!而是给您的复选框标记一个类,并在布局中确保包含包含一些JavaScript的js文件:
$('.myCheckBoxClass').click(function() {
// Make your AJAX call, and then...
var id = // Traverse the DOM to get your feed_item id
$('#task_' + id).hide();
})