Do I need role=“button” on a <button>?

前端 未结 7 672
-上瘾入骨i
-上瘾入骨i 2020-12-15 22:59

I\'ve noticed in all of Bootstrap\'s examples using button elements, they include role=\"button\" (and type=\"button\"), such as:

7条回答
  •  醉梦人生
    2020-12-15 23:23

    According to W3C Html5 Button

    The missing value default is the Submit Button state.

    If the type attribute is in the Submit Button state, the element is specifically a submit button.

    Unless you're going to use buttons to submit a form, you need to explicitly set type="button" as omitting this, as stated in W3C specification, it will act as a submit button, will submit your form. To avoid unnecessary submits, you need to explicitly set type="button" to your

提交回复
热议问题