HTML 5 <button> 标签

定义和用法

<button> 标签定义按钮。

您可以在 button 元素内放置内容,比如文本或图像。这是该元素与通过 input 元素创建的按钮的不同之处。

请始终为按钮规定 type 属性。不同的浏览器根据 type 属性使用不同的默认值。

实例

标记一个按钮:

<button type="button">Click Me!</button>

亲自试一试

HTML 4.01 与 HTML 5 之间的差异

HTML 5 中的新属性:autofocus, form, formaction, formenctype, formmethod, formnovalidate 以及 formtarget。

提示和注释

注释:如果在 HTML 表单中使用 button 元素,不同的浏览器会提交不同的按钮值。请使用 input 元素在 HTML 表单中创建按钮。

属性

new : HTML5 中的新属性。

属性 描述
autofocus autofocus 规定当页面加载时按钮应当自动地获得焦点。
disabled disabled 规定应该禁用该按钮。
form form_name 规定按钮属于一个或多个表单。
formaction url

覆盖 form 元素的 action 属性。

注释:该属性与 type="submit" 配合使用。

formenctype 见注释

覆盖 form 元素的 enctype 属性。

注释:该属性与 type="submit" 配合使用。

formmethod
  • get
  • post

覆盖 form 元素的 method 属性。

注释:该属性与 type="submit" 配合使用。

formnovalidate formnovalidate

覆盖 form 元素的 novalidate 属性。

注释:该属性与 type="submit" 配合使用。

formtarget
  • _blank
  • _self
  • _parent
  • _top
  • framename

覆盖 form 元素的 target 属性。

注释:该属性与 type="submit" 配合使用。

name button_name 规定按钮的名称。
type
  • button
  • reset
  • submit
规定按钮的类型。
value text 规定按钮的初始值。可由脚本进行修改。

注释:formenctype 属性可能的值:

  • application/x-www-form-urlencoded
  • multipart/form-data
  • text/plain

全局属性

<button> 标签支持 HTML 5 中的全局属性

事件属性

<button> 标签支持 HTML 5 中的事件属性