我在这里尝试了很多例子,但我可以让我的代码在删除之前显示一个弹出窗口。我使用的代码可以在这里找到:
答案 0 :(得分:17)
您只需对链接或按钮使用onclick
方法:
<a href="DELETE_PAGE" onClick="return confirm('Delete This account?')">Delete Account</a>
答案 1 :(得分:10)
<script type="text/javascript">
function ConfirmDelete()
{
if (confirm("Delete Account?"))
location.href='linktoaccountdeletion';
}
</script>
echo '<input type="button" onclick="ConfirmDelete()" value="DELETE ACCOUNT">';
答案 2 :(得分:4)
试试这个
<form action="url/to/delation_page" onSubmit="return confirm('are you sure?')">
</form>
答案 3 :(得分:3)
说完
onclick="return confirm('Are you sure you want to delete?')"
^^^^^^ --> this is very important step...
答案 4 :(得分:1)
javascript确认
function doConfirm(id)
{
var ok = confirm("Are you sure to Delete?")
if (ok)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
window.location = "create_dealer.php"; // self page
}
}
xmlhttp.open("GET", "delete_dealer.php?id=" + id);
xmlhttp.send();
}
}
删除按钮
<input type="button" onclick="doConfirm();"/>
答案 5 :(得分:0)
如果你使用on-click,数据将被删除但是要查看结果你必须手动刷新页面而不是使用 onSubmit =“返回确认('你确定吗?')”
认为这有帮助!