How to prevent default on form submit?

后端 未结 2 1247
别那么骄傲
别那么骄傲 2020-12-17 01:30

If I do this I can prevent default on form submit just fine:

document.getElementById(\'my-form\').onsubmit(function(e) {
   e.preventDefault();
   // do some         


        
2条回答
  •  醉梦人生
    2020-12-17 02:11

    i known this is old, but just for the sake of it. try

    document.getElementById('my-form').addEventListener('onsubmit', 
    function(event){event.preventDefault();my_func();});
    var my_func = function() {
    // HOW DO I PREVENT DEFAULT HERE???
    // do something
    }
    

提交回复
热议问题