单击"删除"按钮时,如何从表中获取行值



单击删除按钮时,我正在尝试删除行。

<tbody>
{% for dt in data %}
<tr>
<td>
<i class="fa fa-external-link user-profile-icon"></i>
<a href="{{dt.url}}" target="_blank">{{dt.url}}</a>
</td>
<td>{{dt.modified}}</td>
<td>
<button type="button" class="fa fa-trash-o btn btn-danger" data-toggle="modal" data-target="#exampleModal{{forloop.counter}}">Delete</button>
</td>
<div class="modal fade bd-example-modal-lg" id="exampleModal{{forloop.counter}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModal{{forloop.counter}}">DELETE</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>
Are you sure you want to delete this row
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<button type="submit" class="btn btn-primary">Yes</button>
</div>
</div>
</div>
</div>
</tr>
{% endfor %}
</tbody>

当我点击删除按钮时,会出现模式进行确认,当我点击是时,我必须发送相应删除按钮的{{dt.url}}。我可以使用具有隐藏类型的input标记,并使用{{dt.url}}设置输入值。我无法检查单击了哪个删除按钮。请帮忙。

在表外添加<input type="hidden" name="deletefile" value="" id="deletefileID">

现在将按钮的值设置为{{dt.url}

<button type="button" value="{{dt.url}" class="fa fa-trash-o btn btn-danger" data-toggle="modal" data-target="#exampleModal{{forloop.counter}}">Delete</button>

这是为了在单击删除按钮时使用此值来设置隐藏输入标记的值。


$('.btn-danger').on('click',function(){
var tmp = this;
tmp = tmp.value;
$('#deletefileID').val(tmp);
});

最新更新