Can I make a <button> not submit a form?

前端 未结 8 1332
耶瑟儿~
耶瑟儿~ 2020-11-22 05:36

I\'ve got a form, with 2 buttons



8条回答
  •  耶瑟儿~
    2020-11-22 05:47

    Honestly, I like the other answers. Easy and no need to get into JS. But I noticed that you were asking about jQuery. So for the sake of completeness, in jQuery if you return false with the .click() handler, it will negate the default action of the widget.

    See here for an example (and more goodies, too). Here's the documentation, too.

    in a nutshell, with your sample code, do this:

    
    
    
    
    

    As an added benefit, with this, you can get rid of the anchor tag and just use the button.

提交回复
热议问题