用户单击删除按钮。带有确定和取消的 Javascript 警报框弹出窗口。如果用户单击“确定”,则页面重新加载(发布表单),我需要从此处创建具有值的 php 变量name="confirm_delete"
)
这是我的代码
<form action="<?php echo (htmlspecialchars($_SERVER["PHP_SELF"])) ?>" method="post">
<input name="delete" type="submit" id="delete" value="Delete">
<input type="hidden" name="confirm_delete" id="confirm_delete" value="0" >
<script>
$(document).ready(function() {
$("#delete").click(function(){
var answer = confirm("Are you sure you want to delete?");
if (answer){
return true;
document.getElementById('confirm_delete').value = 1;
} else {
return false;
document.getElementById('confirm_delete').value = 0;
}
});
});
</script>
然后print_r($_POST['confirm_delete']);
但值始终为 0。这意味着它document.getElementById('confirm_delete').value = 1;
不起作用。
请告知需要纠正的地方