SimpleModal Confirm fails to submit form

只愿长相守 提交于 2019-12-24 07:10:11

问题


I'm trying to use jQuery SimpleModal Confirm to show a Yes/No confirmation when a form is submitted.

I had modified the demo here (last in list), as follows, to catch and block the form submission.

However, this only seems to work with jQuery 1.2.6 a recent upgrade to 1.3.2 stops the form from being submitted if yes is clicked.

I can't however, work out what in my code is now wrong / incompatible. The demo (which is a simple window.href implementation works in both versions).

$(document).ready(function () {

$('input.delete').click(function (e) {
        e.preventDefault();
        var target = $(e.target);
        confirm("Really delete this event?", function () {
            target.click()
        });
    });
 });

回答1:


How about something like this? The idea is to catch (and fire!) on the submit event, not the click event.

$(document).ready(function () {
    $('#myForm').submit(function() {
        var f = this;
        confirm("Really delete this event?", function () {
            $(f).submit();
        });
        return false;  // cancel the initial submit event
    });
});

Hope this is of some help. Good luck!




回答2:


Jon,

The demos are the site are using the latest jQuery, so I don't think it is an issue between the version and SimpleModal.

What about trying:

target.submit();

-Eric




回答3:


Got it working with a combination of Funka and Eric's advice:

$(document).ready(function () {  
$('.deleteconfirm').click(function (e) {
         e.preventDefault();
         confirm("Really delete this event?", function () {
         $('form#deleteform').submit()
         });
     });
 });


来源:https://stackoverflow.com/questions/1869188/simplemodal-confirm-fails-to-submit-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!