Confirmation of Form Submission using jQuery

雨燕双飞 提交于 2019-12-25 03:45:53

问题


I want to show an alert box before form submission.

If a user presses yes, then the form will submit, otherwise it wont. Is there a solution using jQuery?


回答1:


you can use the javascript confirm(message) : boolean function by intercepting the submit event of html form.

$("#html_form").submit(function(e){
    if (!confirm("should i really submit"))
    {
        e.preventDefault();
        return;
    } 
});



回答2:


$('#yourform').submit(function(e) {
    if(!confirm('really submit the form?')) {
        e.preventDefault();
        return;
    }
    // submit the form via ajax, e.g. via the forms plugin
    // http://jquery.malsup.com/form/
});



回答3:


Read this post...

Confirmation Posts Yes/No Submit

May be this will help you out.



来源:https://stackoverflow.com/questions/6421293/confirmation-of-form-submission-using-jquery

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