Execute javascript code straight before page submit

后端 未结 5 1529
半阙折子戏
半阙折子戏 2020-12-08 19:24

There are a few similar questions to this but none quite the same.

I want to know if there is an event that can be used to execute some JS before a page is submittin

5条回答
  •  渐次进展
    2020-12-08 20:07

    Something like this?

    function do_something(){ // Do your stuff here }

    If you put return like the code below, you can prevent the form submission by returning false from the do_something() function.

    
    
    function do_something(){
       // Do your stuff here
       return true; // submit the form
    
       return false; // don't submit the form
    }
    

提交回复
热议问题