[英]How to get row value from table when delete button is clicked?
I am trying to delete row when delete button is clicked.单击删除按钮时,我正在尝试删除行。
<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">×</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>
When I click on delete button, modal appear for confirmation and when I click Yes then I have to send the {{dt.url}}
for corresponding delete button.当我单击删除按钮时,会出现确认模式,当我单击是时,我必须发送{{dt.url}}
以获取相应的删除按钮。 I could use the input tag with hidden type and set the input value with {{dt.url}}
.我可以使用隐藏类型的输入标签并使用{{dt.url}}
设置输入值。 I am not able to check which delete button is clicked.我无法检查单击了哪个删除按钮。 Please help.请帮忙。
Add <input type="hidden" name="deletefile" value="" id="deletefileID">
outside your table.在表外添加<input type="hidden" name="deletefile" value="" id="deletefileID">
。
Now set the value of button as {{dt.url}
.现在将按钮的值设置为{{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>
This is to use this value to set value of hidden input tag whenever delete button is clicked.这是为了在单击删除按钮时使用此值来设置隐藏输入标签的值。
$('.btn-danger').on('click',function(){
var tmp = this;
tmp = tmp.value;
$('#deletefileID').val(tmp);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.