我有以下代码行
$product_list="$product_list $id - $product_name - $date_added <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br/>"
和
if(isset($_GET['deleteid']))
{
echo 'Do you really want to delete this item with ID of '.$_GET['deleteid']. '? <a href = "inventory_list.php?yesdelete='.$_GET['deleteid']. '"> Yes</a> | <a href="inventory_list.php"> No</a>';
exit();
}
如何让它显示为对话框,您认为使用对话框而不是转到确认页面会是一个不错的选择吗?
更新
我尝试了以下操作,但是当deleteid设置时,它会创建另一个新的删除链接,如何让现有的删除链接显示确认框?
if(isset($_GET['deleteid']))
{
echo '<a href="inventory_list.php?yesdelete='.$_GET['deleteid']. '" onClick="return confirm(\'Do you want to delete?\');">Delete</a>';
}
更新尝试
$product_list="$product_list $id - $product_name - $date_added <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$_GET[deleteid]' onClick='return confirm(\'Do you want to delete?\');'>Delete</a><br/>"
似乎没有效果。
答案 0 :(得分:0)
<script>
var el = document.getElementById('deleteLink');
el.onclick = reallyDelete();
function reallyDelete(){
var verifyDelete = confirm("Really wanna delete?");
if (verifyDelete == false) {
e.preventDefault();
}
}
</script>
然后你当然必须将ID(deleteLink)添加到A链接,这也只有在有一个链接指向&#34;删除&#34;否则你可能需要使用onClick,但我建议谷歌搜索一下如何为你找到最佳解决方案的教程。
(还有Bootstrap)
<强>更新强>
替换
<a href='inventory_list.php?deleteid=$id'>delete</a>
与
<a href="inventory_list.php?yesdelete='.$id. '" onClick="return confirm(\'Do you want to delete?\');">Delete</a>
并删除此内容:
if(isset($_GET['deleteid']))
{
echo '<a href="inventory_list.php?yesdelete='.$_GET['deleteid']. '" onClick="return confirm(\'Do you want to delete?\');">Delete</a>';
}