我在提交表单之前试图让网站返回确认对话框,但由于某种原因它无法正常工作。它返回了确认对话框,但点击“是”后,它不会提交表单。我做错了什么?
<?php
echo "
<form action = 'delete.php' method = 'POST'>
<label id = 'delete' onclick = \"return confirm('Are you sure?');this.form.submit()\"> delete </label>
</form>
";
?>
注意:
而不是使用input:submit,我宁愿使用标签onclick()和确认对话框。那可能吗?感谢。
答案 0 :(得分:1)
代码中的onclick
处理程序只返回confirm
对话框结果,并忽略代码的其余部分(this.form.submit()
);
我建议在这种情况下使用外部函数:
<?php
echo "
<form action = 'delete.php' method = 'POST'>
<label id = 'delete' onclick = \"confirmSubmit(this);\"> delete </label>
</form>
";
?>
js code:
function confirmSubmit(e){
var need_submit = confirm('Are you sure?');
if (need_submit) e.form.submit();
}