Confirmation of Form Submission using jQuery

2019-09-05 02:21发布

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?

3条回答
ゆ 、 Hurt°
2楼-- · 2019-09-05 03:03

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;
    } 
});
查看更多
Bombasti
3楼-- · 2019-09-05 03:05
$('#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/
});
查看更多
做个烂人
4楼-- · 2019-09-05 03:13

Read this post...

Confirmation Posts Yes/No Submit

May be this will help you out.

查看更多
登录 后发表回答