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 元素的 enctype 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formenctype | 見注釋 | 覆蓋 form 元素的 action 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formmethod |
| 覆蓋 form 元素的 method 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formnovalidate | formnovalidate | 覆蓋 form 元素的 novalidate 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formtarget |
| 覆蓋 form 元素的 target 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
name | button_name | 規定按鈕的名稱。 |
type |
| 規定按鈕的類型。 |
value | text | 規定按鈕的初始值??捎赡_本進行修改。 |
注釋:formenctypeNew 屬性可能的值:
- application/x-www-form-urlencoded
- multipart/form-data
- text/plain
全局屬性
<button> 標簽支持 HTML 5 中的全局屬性。
事件屬性
<button> 標簽支持 HTML 5 中的事件屬性。