--- title: slug: Web/HTML/Element/Input/button translation_of: Web/HTML/Element/input/button ---
{{HTMLRef}}
元素<input type="button">
是 <input>
元素的特殊版本,被用来创建一个没有默认值的可点击按钮。 它已经在HTML5被 <button>元素取代
浏览器生成一个控件没有默认值的可点击按钮。该按钮上可有任何标签。该控件在不同的浏览器上,可能有不同的样式。
Content categories | Flow content, phrasing content, Interactive content, listed, labelable, and submittable form-associated element, palpable content. |
---|---|
Permitted content | Phrasing content. |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parent elements | Any element that accepts phrasing content. |
DOM interface | HTMLButtonElement |
元素属性 | 行内元素 |
This element can have any of the global attributes in addition to the following:
This Boolean attribute indicates that the user cannot interact with the button. If this attribute is not specified, the button inherits its setting from the containing element, for example {{HTMLElement("fieldset")}}; if there is no containing element with the disabled
attribute set, then the button is enabled. The disabled control's value isn't submitted with the form and the click
event will not be dispatched on disabled controls.
Firefox will, unlike other browsers, by default, persist the dynamic disabled state of a {{HTMLElement("button")}} across page loads. Use the {{htmlattrxref("autocomplete","button")}} attribute to control this feature.
off
(i.e., autocomplete="off"
) disables this feature.<button>
element must be a descendent of a form element. This attribute enables you to place <button>
elements anywhere within a document, not just as descendents of their {{HTMLElement("form")}} elements.formenctype
attribute specifies the type of content that is used to submit the form to the server. Possible values are:
application/x-www-form-urlencoded
: The default value if the attribute is not specified.multipart/form-data
: This value is used if an {{HTMLElement("input")}} element is used with the {{htmlattrxref("type","input")}} attribute set to file
.text/plain
If this attribute is specified, it overrides the {{htmlattrxref("enctype","form")}} attribute of the element's form owner.
formmethod
attribute specifies the HTTP method that the browser uses to submit the form. Possible values are:
post
: The data from the form is included in the body of the form and is sent to the server.get
: The data from the form is appended to the form attribute URI, with a '?' as a separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.If specified, this attribute overrides the {{htmlattrxref("method","form")}} attribute of the element's form owner.
formnovalidate
attribute specifies that the form is not to be validated when it is submitted. If this attribute is specified, it overrides the {{htmlattrxref("novalidate","form")}} attribute of the element's form owner. This is a Boolean attribute.formtarget
attribute is a name or keyword indicating where to display the response that is received after submitting the form. This is a name of, or keyword for, a browsing context (for example, tab, window, or inline frame). If this attribute is specified, it overrides the {{htmlattrxref("target", "form")}} attribute of the element's form owner. The following keywords have special meanings:
self
: Load the response into the same browsing context as the current one. This value is the default if the attribute is not specified._blank
: Load the response into a new unnamed browsing context._parent
: Load the response into the parent browsing context of the current one. If there is no parent, this option behaves the same way as _self
._top
: Load the response into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self
.submit
: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.reset
: The button resets all the controls to their initial values.button
: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.这创建一个新的按钮<input>元素,文本显示出 'Click me'。
<input type="button" value="Click me">
Specification | Status |
{{SpecName('HTML WHATWG', 'the-button-element.html#the-button-element', '<button>')}} | {{Spec2('HTML WHATWG')}} |
{{SpecName('HTML5 W3C', 'forms.html#the-button-element', '<button>')}} | {{Spec2('HTML5 W3C')}} |
{{SpecName('HTML4.01', 'interact/forms.html#h-17.5', '<button>')}} | {{Spec2('HTML4.01')}} |
{{CompatibilityTable}}
Feature | Google Chrome | Firefox (Gecko) |
IE |
Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
formenctype attribute |
9.0 | {{CompatGeckoDesktop("2.0")}} | 10 | 10.6 | {{CompatUnknown}} |
formmethod attribute |
9.0 | {{CompatGeckoDesktop("2.0")}} | 10 | {{CompatUnknown}} | {{CompatUnknown}} |
autofocus attribute |
9.0 | {{CompatGeckoDesktop("2.0")}} | 10 | 9.6 | 5.0 |
formaction attribute |
9.0 | {{CompatGeckoDesktop("2.0")}} | 10 | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Firefox 移动版(Gecko) | IE 移动版 | Opera 移动版 | Safari 移动版 |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
formenctype attribute |
{{CompatUnknown}} | {{CompatGeckoMobile("2.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
formmethod attribute |
{{CompatUnknown}} | {{CompatGeckoMobile("2.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
formaction attribute |
{{CompatUnknown}} | {{CompatGeckoMobile("2.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |