这是一个用于待办事项列表的复选框。
使用之前
<%= 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();
})
关于javascript - 如何在rails中将远程功能与check_box_tag一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4293505/