Form is submitted when I click on the button in form. How to avoid this?

后端 未结 3 594
天命终不由人
天命终不由人 2020-11-27 04:26

I use twitter-boostrap and I\'d like to use these radio-buttons in my form. The problem is when I click on any of these buttons, the form is immediately submitted. How to av

3条回答
  •  迷失自我
    2020-11-27 05:23

    From the fine HTML5 specification:

    A button element with no type attribute specified represents the same thing as a button element with its type attribute set to "submit".

    And a

    are the same as these (in compliant browsers):

    
    
    

    and any time you hit one of those buttons you'll submit your form.

    The solution is to use plain buttons:

    
    
    

    Some versions of IE default to type="button" despite what the standard says. You should always specify the type attribute when using a

提交回复
热议问题