我为页面上的删除按钮创建了一个弹出模式。当您单击删除按钮时,将弹出一个模态对话框,询问您是否真的要删除该项目。模态上有两个按钮,第一个是取消,另一个是删除。单击取消按钮将关闭弹出窗口,但是当我单击删除按钮时,什么也没有发生。
这是删除按钮的php代码:
echo "<a href='#myModal' class='btn btn-danger' data-toggle='modal'> Delete</a>";
这是模式代码:
<div id="myModal" class="modal fade">
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header">
<div class="icon-box">
<i class="material-icons"></i>
</div>
<h4 class="modal-title">Are you sure?</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<p>Do you really want to delete these records? This process cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="confirm">Delete</button>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
单击删除按钮后您什么都没有给出,您期望什么?如果为按钮添加data-dismiss =“ modal”,它将关闭弹出窗口。您可以使用javascript处理其余的事情。
function Delete()
{
//Write your code for deleting
$.ajax({
type: "post",
datatype: "json",
async: false,
contenttype: "application/json",
url: "DeleteItem.php",
success: function (result) {
$('#myModal').modal('hide'); //for hiding popup
},
error: function(xhr, ajaxOptions, thrownError) {
//handle error
}
});
}
<div id="myModal" class="modal fade">
<div class="modal-dialog modal-confirm">
<div class="modal-content">
<div class="modal-header">
<div class="icon-box">
<i class="material-icons"></i>
</div>
<h4 class="modal-title">Are you sure?</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<p>Do you really want to delete these records? This process cannot be undone.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" onclick="Delete()" id="confirm">Delete</button>
</div>
</div>
</div>
</div>