Latest web development tutorials

HTML <button> 標籤

實例

以下代碼標記一個按鈕:

<button type="button">点我!</button>

嘗試一下»

瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流瀏覽器都支持<button> 標籤。


標籤定義及使用說明

<button> 標籤定義一個按鈕。

在<button> 元素內部,您可以放置​​內容,比如文本或圖像。 這是該元素與使用<input> 元素創建的按鈕之間的不同之處。

提示:請始終為<button>元素規定type屬性。不同的瀏覽器對<button> 元素的type 屬性使用不同的默認值。


提示和註釋

註釋:如果在HTML表單中使用<button>元素,不同的瀏覽器可能會提交不同的按鈕值。請使用<input>在HTML表單中創建按鈕。


HTML 4.01 與HTML5之間的差異

HTML5 中的新屬性:autofocus、form、formaction、formenctype、formmethod、formnovalidate 以及formtarget。


屬性

New :HTML5中的新屬性。

属性 描述
autofocus New autofocus 规定当页面加载时按钮应当自动地获得焦点。
disabled disabled 规定应该禁用该按钮。
form New form_id 规定按钮属于一个或多个表单。
formaction New URL 规定当提交表单时向何处发送表单数据。覆盖 form 元素的 action 属性。该属性与 type="submit" 配合使用。
formenctype New application/x-www-form-urlencoded
multipart/form-data
text/plain
规定在向服务器发送表单数据之前如何对其进行编码。覆盖 form 元素的 enctype 属性。该属性与 type="submit" 配合使用。
formmethod New get
post
规定用于发送表单数据的 HTTP 方法。覆盖 form 元素的 method 属性。该属性与 type="submit" 配合使用。
formnovalidate New formnovalidate 如果使用该属性,则提交表单时不进行验证。覆盖 form 元素的 novalidate 属性。该属性与 type="submit" 配合使用。
formtarget New _blank
_self
_parent
_top
framename
规定在何处打开 action URL。覆盖 form 元素的 target 属性。该属性与 type="submit" 配合使用。
name name 规定按钮的名称。
type button
reset
submit 
规定按钮的类型。
value text 规定按钮的初始值。可由脚本进行修改。


全局屬性

<button>標籤支持HTML的全局屬性


事件屬性

<button>標籤支持HTML的事件屬性


相關文章

HTML DOM參考手冊: Button對象