Using JQuery - preventing form from submitting

后端 未结 13 2957
灰色年华
灰色年华 2020-11-22 06:51

How do I prevent a form from submitting using jquery?

I tried everything - see 3 different options I tried below, but it all won\'t work:

    $(docu         


        
13条回答
  •  独厮守ぢ
    2020-11-22 07:09

    Using jQuery, you can do the following:

    1- Use the native form submit event with a Submit button, while preventing the event from firing, then

    2- Check the form Valid property This can be implemented as following:

    1- HTML:

     

    2- Javascript

     $("form").on("submit", function (e) {
            e.preventDefault();
            if ($(this).valid()) {  
               alert('Success!');
            }
        });
    

提交回复
热议问题