我在这里浏览时没有太多运气,我有多种形式(记录数量有所不同),我想在提交表格之前要求确认。
代码:
$(function() {
$(".delete_button").click(function(){
if (confirm("Click OK to continue?")){
$('form').submit();
}
});
});

{% for blog in blogs %}
<tr>
<td>{{blog.getTitle}}</td>
<td class="hidden-xs hidden-sm hidden-md">{{blog.getCreatedAt|date("j - n - Y, g:i a")}}</td><!--("F j, Y, g:i a")-->
<td>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">{% trans %}table_actions_text{% endtrans %} <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li><a href="#"><i class="fa fa-edit"></i>{% trans %}edit_text{% endtrans %}</a></li>
<li class="divider"></li>
<li> <div class="form-group"><form id="whateverid" class="form-inline" method="post" action="{{path('deleteBlogPost')}}"><button <button type="submit" class="btn btn-danger delete_button"><i class="fa fa-trash"></i> <input name="id" id="id" type="hidden" value="{{blog.getId}}">{% trans %}delete_text{% endtrans %}</button></form></div></li>
</ul>
</div>
</td>
</tr>
{% endfor %}
&#13;
我如何确保它提交当前的表格,而不是其他任何表格?
答案 0 :(得分:1)
找到删除按钮的父表单元素并提交
$(this).closest("form").submit();