繁体   English   中英

提交表单前无法返回确认对话框

[英]Returning a confirmation dialog before submitting form not working

我正在尝试让网站在提交表单之前返回确认对话框,但是由于某些原因,它无法正常工作。 它返回了确认对话框,但是单击“是”后,它不提交表单。 我究竟做错了什么?

<?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()和确认对话框。 那可能吗? 谢谢。

您代码中的onclick处理程序仅返回confirm对话框结果,并忽略代码的其余部分( this.form.submit()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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM