How to prevent form from being submitted?

后端 未结 10 2341
挽巷
挽巷 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:36

    You can use inline event onsubmit like this

    Or

    
    
    
    

    Demo

    Now, this may be not a good idea when making big projects. You may need to use Event Listeners.

    Please read more about Inline Events vs Event Listeners (addEventListener and IE's attachEvent) here. For I can not explain it more than Chris Baker did.

    Both are correct, but none of them are "best" per se, and there may be a reason the developer chose to use both approaches.

提交回复
热议问题