问题:单击时显示/隐藏javascript函数,打开所有do循环结果。我需要它只打开“编辑”在/单击的一个结果。
窗体文本字段被隐藏,直到单击“编辑”为止。该表可以有多个结果,因此当表有2+结果时,单击“编辑”按钮可以处理所有的循环结果,而不仅仅是单击它所单击的结果。
html:
<div class="form-show"><a href="" id="form-show">Edit</a></div>
<div id="form-hide">
<!--form and text_field-->
</div>
Javascript:
$(function() {
$('a#form-show').click(function(event){
event.preventDefault();
$('div#form-hide').toggle();
});
});
表单是一个do循环(通过结果循环)。
我如何修改javascript,以便当用户单击"Edit“时,只能编辑1的结果而不是所有的结果?
整体表单:
<td class="center ">
<div class="form-show"><%= user.field %>% <a href="" id="form-show">Edit</a></div>
<div id="form-hide">
<%= form_for user, remote: true do |f| %>
<%= f.text_field :field, class: "form-cotrol" %>
<%= f.button data: {confirm: "Are you sure?"}, class: "btn btn-light " do %>
<i class="fa fa-pencil" aria-hidden="true"></i>
<% end %>
<% end %>
</div>
</td>
发布于 2019-01-13 00:41:01
只需使用.next()
查找下一个可编辑的div:
$(function() {
$('a#form-show').click(function(event){
event.preventDefault();
event.target.next($('div#form-hide')).toggle();
});
});
https://stackoverflow.com/questions/54165153
复制相似问题