有人可以帮我处理我的代码吗?每当我想从我的表中删除数据时,如果我想删除该项目,则会弹出一个对话框,但是当我按下取消按钮时仍然会删除该项目..这是我的代码
echo"<td> <center><a href ='delete.php?house_id=$id'><button type='button' onclick='ConfirmDelete()'' class='btn btn-info btn-md'><span class='glyphicon glyphicon-trash'></span>Delete</button></a></center></td>";
echo"</tr>";
$count++;
}
?>
<script type="text/javascript">
function ConfirmDelete(){
if (confirm("Delete Account?"))
location.href='delete.php';
}
</script>
答案 0 :(得分:1)
试试这个:
<script type="text/javascript">
function ConfirmDelete(){
if (confirm("Delete Account?")){
location.href='delete.php';
}
else {
return false;
}
}
</script>
并更新onclick='return ConfirmDelete()'
答案 1 :(得分:0)
关闭你的功能
<script type="text/javascript">
function ConfirmDelete(){
if (confirm("Delete Account?"))
location.href='delete.php';
}
}
</script>
答案 2 :(得分:0)
您的代码中存在语法错误。改变这一部分:
function ConfirmDelete(){
if (confirm("Delete Account?")){
location.href='delete.php';
}
}