How to prevent form from being submitted?

后端 未结 10 2363
挽巷
挽巷 2020-11-21 07:06

I have a form that has a submit button in it somewhere.

However, I would like to somehow \'catch\' the submit event and prevent it from occurring.

Is there s

10条回答
  •  无人及你
    2020-11-21 07:23

    Try this one...

    HTML Code

    jQuery Code

    $(function(){
        $('.submit').on('submit', function(event){
            event.preventDefault();
            alert("Form Submission stopped.");
        });
    });
    

    or

    $(function(){
        $('.submit').on('submit', function(event){
           event.preventDefault();
           event.stopPropagation();
           alert("Form Submission prevented / stopped.");
        });
    });
    

提交回复
热议问题