我有一个用户列表,除了删除按钮。当您单击删除按钮时,将出现confirm()脚本。我使用了这段代码,但被删除的代码始终是最后一个ID。
button onclick="myFunction()">Delete</button></td>
<script>
function myFunction() {
if(confirm("Are you sure you want to delete this?") == true) {
window.location.href = "delete.php?id=<?php echo $r->id); ?>";
} else {
//
}
}
</script>
答案 0 :(得分:0)
您可以使用:
<button onclick="myFunction(<?php echo $r->id; ?>)">Delete</button></td>
<script>
function myFunction(id) {
if(confirm("Are you sure you want to delete this?") == true) {
window.location.href = "delete.php?id="+id;
} else {
//
}
}
</script>