【问题标题】:Returning a confirmation dialog before submitting form not working在提交表单之前返回确认对话框不起作用
【发布时间】:2016-01-02 20:33:57
【问题描述】:

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

<?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。那可能吗?谢谢。

【问题讨论】:

    标签: javascript php forms form-submit confirm


    【解决方案1】:

    代码中的onclick 处理程序只返回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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2011-01-18
      • 2014-09-22
      相关资源
      最近更新 更多