我正在表上显示一些动态值。表中的每一行都有一个删除按钮(假设按钮A)。如果单击删除按钮(按钮A),则打开一个模式以确认删除,并且有确认按钮(按钮B)。从确认按钮中,我正在调用api来删除具有实体ID的实体。
现在我在按钮A上有ID,并且正在从按钮B发送请求。如何将ID从按钮A发送到按钮B。
按钮A:
<td>
<button data-toggle="modal" value = {{this.id}} data-target="#myModal">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</td>
带有按钮B的模式:
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Confirm Delete</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-header">
Are you sure you want to delete the entry?
</div>
<div class="modal-footer">
<a href="/admin/dashbord/category/[id will be here ]/delete" class="btn btn-danger">yes</a>
</div>
</div>
</div>
</div>
我已经给出了按钮B的{{this.id}} on the url
,但是它总是删除top or last
元素?
答案 0 :(得分:1)
将一个类(例如.delete)添加到按钮
<button data-toggle="modal" value ={{this.id}} class="delete" data-target="#myModal">
<i class="fa fa-trash-o" aria-hidden="true">delete</i>
</button>
然后将一个类添加到确认链接(例如.yes):
<a href="/admin/dashbord/category/[id will be here ]/delete" class="btn btn-danger yes">yes</a>
然后在按钮上获取onclick事件,并获取按钮的值并将其插入href属性:
$(document).on("click", ".delete", function () {
var value = $(this).val();
console.log("value : ", $(this).val())
$(".modal-dialog .yes").attr("href","/admin/dashbord/category/"+value+"/delete");
});
查看此codepen