event.preventDefault() working in Chrome, not Firefox for a submit button

后端 未结 5 1022
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 06:11

I have the following submit button:

 

When I use the follo

相关标签:
5条回答
  • 2021-01-18 06:20

    You need make sure you add event to the parameter list of the event function. I think some browsers have a global event, that's why it works in some browsers.

    $(document).ready(function(){
       $("#submit").submit(function(event){  // The event is passed to this function
          event.preventDefault();
          console.log('test');
       }
    });
    
    0 讨论(0)
  • 2021-01-18 06:23

    You did not add the event to the function parameters.
    fixed version:

    $(document).ready(function(){
            $("#submit").submit(function(event){
                    event.preventDefault();
                    console.log('test');
            }
    });
    
    0 讨论(0)
  • 2021-01-18 06:34

    Have you tried passing the event through as a variable?

    $(document).ready(function(){
        $("#submit").submit(function(e){
                e.preventDefault();
                console.log('test');
        }
     });
    
    0 讨论(0)
  • 2021-01-18 06:40

    Pass the event parameter in the function callback Try this

    $(document).ready(function(){
            $("#submit").submit(function(event){
                    event.preventDefault();
                    console.log('test');
            }
    });
    
    0 讨论(0)
  • 2021-01-18 06:42

    Simply in the function onclick for the submit button write down like this

    onclick="return myfunction();"
    

    and inside the function statements

    myfunction () {
    return false;};
    
    0 讨论(0)
提交回复
热议问题