如何中断表单发布,直到按下确认按钮

How to interrupt the form posting , until pressing the confirm button?

本文关键字:按钮 确认 何中断 中断 表单      更新时间:2023-09-26

有这样一种形式:

<form action="" method="post">
   <input type="submit" value="Delete Me">
</form>

我想把它改为,当按下提交按钮时,打开一个警告模式,如果在模式上按下"确认",则表单处理。

一些尝试代码,但我想知道在中断表单过程后有没有办法"继续"表单过程,非常感谢。

    $(function () {
        $('.delete_form').on("submit",function(){
            $('#deleteModal').modal('toggle');
            return false; //pause the submit
        });
        $('.confirm_del').on("click",function(){
            return true; //process the form submit
        });
    });

使用以下代码。按钮从提交按钮更改为普通按钮。。

<form action="" method="post" id="f1">
   <input type="button" id="b1" value="Delete Me">
</form>
<script>
  $('#b1').click(function(){
        $('#deleteModal').modal('toggle');
  });
  $('.confirm_del').on("click",function(){
         $("#f1").submit(); //process the form submit
  });
</script>

更改

type="submit" to  type="button" 

然后使用其id或类添加事件侦听器,然后打开警告警报并提交其响应值的表单。

您的脚本应该是这样的:

$(function () {
    $('.delete_form').on("submit",function(){
        return confirm('Are You Sure');
    });
});

试试这个,

 <form action="" method="post" onsubmit="return isDeleteConfirm()">
       <input type="submit" value="Delete Me">
 </form>
function isDeleteConfirm(){
        $('.delete_form').on("submit",function(){
            $('#deleteModal').modal('toggle');
            return false; //pause the submit
        });
        $('.confirm_del').on("click",function(){
            return true; //process the form submit
        });
}
<form id="theform">
<button onclick="check()">Send</button>
<script>
function check(){
//display warning
}
function ok(){
//call on ok press
document.getElementById("theform").submit();
}
</script>

只是在用户接受警告之前不要启动提交过程。。。

您还可以在单击确认按钮时触发表单的提交事件。

     $('.confirm_del').on("click",function(){
       $('.delete_form').trigger("submit")
     });