HTMLButtonElement

HTMLButtonElement interface provides properties and methods (beyond the regular HTMLElement interface it also has available to it by inheritance) for manipulating <button> elements.

特性

Inherits properties from its parent, HTMLElement .

HTMLButtonElement.accessKey
DOMString indicating the single-character keyboard key to give access to the button.
HTMLButtonElement.autofocus
Boolean indicating whether or not the control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified.
HTMLButtonElement.disabled
Boolean indicating whether or not the control is disabled, meaning that it does not accept any clicks.
HTMLButtonElement.form 只读
HTMLFormElement reflecting the form that this button is associated with. If the button is a descendant of a form element, then this attribute is the ID of that form element.
If the button is not a descendant of a form element, then the attribute can be the ID of any form element in the same document it is related to, or the null value if none matches.
HTMLButtonElement.formAction
DOMString reflecting the URI of a resource that processes information submitted by the button. If specified, this attribute overrides the action attribute of the <form> element that owns this element.
HTMLButtonElement.formEnctype
DOMString reflecting the type of content that is used to submit the form to the server. If specified, this attribute overrides the enctype attribute of the <form> element that owns this element.
HTMLButtonElement.formMethod
DOMString reflecting the HTTP method that the browser uses to submit the form. If specified, this attribute overrides the method attribute of the <form> element that owns this element.
HTMLButtonElement.formNoValidate
Boolean indicating that the form is not to be validated when it is submitted. If specified, this attribute overrides the novalidate attribute of the <form> element that owns this element.
HTMLButtonElement.formTarget
DOMString reflecting a name or keyword indicating where to display the response that is received after submitting the form. If specified, this attribute overrides the target attribute of the <form> element that owns this element.
HTMLButtonElement.labels 只读
NodeList that represents a list of <label> elements that are labels for this button.
HTMLButtonElement.menu
HTMLMenuElement representing the menu element to be displayed if the button is clicked and is of type="menu" .
HTMLButtonElement.name
DOMString representing the name of the object when submitted with a form. HTML5 If specified, it must not be the empty string.
HTMLButtonElement.tabIndex
long that represents this element's position in the tabbing order.
HTMLButtonElement.type
DOMString indicating the behavior of the button. This is an enumerated attribute with the following possible values:
  • submit : The button submits the form. This is the default value if the attribute is not specified, HTML5 or if it is dynamically changed to an empty or invalid value.
  • reset : The button resets the form.
  • button : The button does nothing.
  • menu : The button displays a menu.
HTMLButtonElement.willValidate 只读
Boolean indicating whether the button is a candidate for constraint validation. It is false if any conditions bar it from constraint validation, including: its type 特性为 reset or button ; it has a <datalist> ancestor; or the disabled property is set to true .
HTMLButtonElement.validationMessage 只读
DOMString representing the localized message that describes the validation constraints that the control does not satisfy (if any). This attribute is the empty string if the control is not a candidate for constraint validation ( willValidate is false ), or it satisfies its constraints.
HTMLButtonElement.validity 只读
ValidityState representing the validity states that this button is in.
HTMLButtonElement.value
DOMString representing the current form control value of the button.

方法

Inherits methods from its parent, HTMLElement

Name Return Type 描述
checkValidity() Boolean Not supported for reset or button elements.
reportValidity() Boolean Not supported for reset or button elements.
setCustomValidity(in DOMString error) void Not supported for reset or button elements.

With Gecko-based browser, use the :-moz-submit-invalid pseudo-class to style submit buttons based on the validation of a form.

规范

规范 状态 Comment
HTML Living Standard
The definition of 'HTMLButtonElement' in that specification.
实时标准
HTML 5.2
The definition of 'HTMLButtonElement' in that specification.
Recommendation menu attribute and type="menu" value have been removed.
HTML 5.1
The definition of 'HTMLButtonElement' in that specification.
Recommendation The following attribute has been added: menu .
type attribute can take one more value, " menu ".
HTML5
The definition of 'HTMLButtonElement' in that specification.
Recommendation The attributes tabindex and accesskey , are now defined on HTMLElement .
The following attributes have been added: autofocus , formAction , formEnctype , formMethod , formNoValidate , formTarget , labels , validity , validationMessage ,和 willValidate .
The following methods have been added: checkValidity() , setCustomValidity() .
type attribute is no more read-only.
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'HTMLButtonElement' in that specification.
Obsolete No change from Document Object Model (DOM) Level 1 Specification .
Document Object Model (DOM) Level 1 Specification
The definition of 'HTMLButtonElement' in that specification.
Obsolete 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
HTMLButtonElement Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
accessKey Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
autofocus Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
disabled Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
form Chrome Yes Edge 16 Firefox 4 IE No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
formAction Chrome Yes Edge 12 Firefox 4
4
In Firefox 56, the implementation has been updated so that the formAction property returns the correct form submission URL, as per spec, when the associated button is being used to submit a form ( bug 1366361 ).
IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4
4
In Firefox 56, the implementation has been updated so that the formAction property returns the correct form submission URL, as per spec, when the associated button is being used to submit a form ( bug 1366361 ).
Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
formEnctype Chrome Yes Edge 12 Firefox 4 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
formMethod Chrome Yes Edge 12 Firefox 4 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
formNoValidate Chrome Yes Edge 12 Firefox 4 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
formTarget Chrome Yes Edge 12 Firefox 4 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
labels Chrome Yes Edge 18 Firefox 56 IE ? Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 56 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
menu
Chrome No Edge No Firefox No IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
name Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
reportValidity Chrome 40 Edge 17 Firefox 49 IE No Opera 27 Safari 10 WebView Android 40 Chrome Android 40 Firefox Android 64 Opera Android 27 Safari iOS 10 Samsung Internet Android 4.0
tabIndex Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
type Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
validationMessage Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
validity Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
value Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
willValidate Chrome Yes Edge 12 Firefox 1 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
见实现注意事项。

另请参阅

  • HTML element implementing this interface: <button>
  1. HTMLButtonElement
  2. 特性
    1. labels
  3. 继承:
    1. HTMLElement
    2. Element
    3. Node
    4. EventTarget
  4. Related pages for HTML DOM
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLCanvasElement
    13. HTMLContentElement
    14. HTMLDListElement
    15. HTMLDataElement
    16. HTMLDataListElement
    17. HTMLDialogElement
    18. HTMLDivElement
    19. HTMLDocument
    20. HTMLElement
    21. HTMLEmbedElement
    22. HTMLFieldSetElement
    23. HTMLFormControlsCollection
    24. HTMLFormElement
    25. HTMLFrameSetElement
    26. HTMLHRElement
    27. HTMLHeadElement
    28. HTMLHeadingElement
    29. HTMLHtmlElement
    30. HTMLIFrameElement
    31. HTMLImageElement
    32. HTMLInputElement
    33. HTMLIsIndexElement
    34. HTMLKeygenElement
    35. HTMLLIElement
    36. HTMLLabelElement
    37. HTMLLegendElement
    38. HTMLLinkElement
    39. HTMLMapElement
    40. HTMLMediaElement
    41. HTMLMetaElement
    42. HTMLMeterElement
    43. HTMLModElement
    44. HTMLOListElement
    45. HTMLObjectElement
    46. HTMLOptGroupElement
    47. HTMLOptionElement
    48. HTMLOptionsCollection
    49. HTMLOutputElement
    50. HTMLParagraphElement
    51. HTMLParamElement
    52. HTMLPictureElement
    53. HTMLPreElement
    54. HTMLProgressElement
    55. HTMLQuoteElement
    56. HTMLScriptElement
    57. HTMLSelectElement
    58. HTMLShadowElement
    59. HTMLSourceElement
    60. HTMLSpanElement
    61. HTMLStyleElement
    62. HTMLTableCaptionElement
    63. HTMLTableCellElement
    64. HTMLTableColElement
    65. HTMLTableDataCellElement
    66. HTMLTableElement
    67. HTMLTableHeaderCellElement
    68. HTMLTableRowElement
    69. HTMLTableSectionElement
    70. HTMLTemplateElement
    71. HTMLTextAreaElement
    72. HTMLTimeElement
    73. HTMLTitleElement
    74. HTMLTrackElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. History
    80. ImageData
    81. Location
    82. MessageChannel
    83. MessageEvent
    84. MessagePort
    85. Navigator
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers