【发布时间】:2015-01-30 05:37:47
【问题描述】:
所以我试图让我的f.submit 在我点击f.check_box 时被触发。我不知道您是否可以使用 jquery 来处理 ruby... 但基本上这是一个包含页面上所有项目的待办事项列表的视图。当我单击复选框将其标记为关闭时,我希望它自动提交。
我想我可以在f.check_box 和f.submit 上分配一个div 标签来触发它们...这是我使用的第一个JQuery。
<h1><%= @list.title %></h1>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<div>
<h2><% @list.items.each do |item| %></h2>
<%= item.content %>
<%= form_for([@list, item]) do |f| %>
<div id="target">
<%= f.check_box :complete %>
</div>
<div id="handler">
<%= f.submit %>
<% end %>
</div>
<% end %>
</div>
<script>
jQuery(document).ready(function() {
jQuery("#target").click(function() {
jQuery("#handler").click();
});
});
</script>
<% if policy(@list).update? %>
<%= link_to "Edit List", edit_list_path, class: 'btn btn-success' %>
<% end %>
<div class="col-md-4">
<% if policy(Item.new).create? %>
<%= link_to "New Item", new_list_item_path(@list), class: 'btn btn-success' %>
<% end %>
<% if policy(@list).destroy? %>
<%= link_to "Delete List", @list, method: :delete, class: 'btn btn-danger', data: { confirm: 'Are you sure you want to destroy this lovely list?'} %>
<% end %>
</div>
</div>
<%= render "items/form" %>
<!--
new_list_item_path
/lists/5/items/new
-->
【问题讨论】:
标签: javascript jquery html ruby-on-rails ruby