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