Jquery trap form submit()

前端 未结 4 1718
长情又很酷
长情又很酷 2021-01-02 00:58

I\'m currently using jquery to trap the submission of a form and show users a dialog for confirmation. If user clicks yes, then form should submit. If user clicks no, then c

4条回答
  •  旧巷少年郎
    2021-01-02 01:37

    You should return false when OK:

    $("#myform").submit(function (event) {
        if (something) {
            var $dialog = $('
    ').dialog({ buttons: { "OK": function () { $dialog.dialog('close'); $("#myform").submit(); return false; // <=== not just return; }, Cancel: function () { $(this).dialog("close"); } } }); $dialog.dialog('open'); event.preventDefault(); return false; } else { $("#myform").submit(); } });

    Or delete the manual submit:

    buttons: {
    "OK": function () {
        $dialog.dialog('close');
        //$("#myform").submit();  <-- delete it
        return;
    },
    

提交回复
热议问题