Using JQuery - preventing form from submitting

后端 未结 13 2682
灰色年华
灰色年华 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:34

    When I am using <form> tag without the attribute id="form" and call it by its tag name directly in jquery it works with me.
    your code in html file :

    <form action="page2.php" method="post">
    

    and in Jquery script:

    $(document).ready(function() {
          $('form').submit(function(evt){
              evt.preventDefault();// to stop form submitting
          });
     });
    
    0 讨论(0)
提交回复
热议问题