HTML 5 <button> 標(biāo)簽
定義和用法
<button> 標(biāo)簽定義按鈕。
您可以在 button 元素內(nèi)放置內(nèi)容,比如文本或圖像。這是該元素與通過 input 元素創(chuàng)建的按鈕的不同之處。
請始終為按鈕規(guī)定 type 屬性。不同的瀏覽器根據(jù) type 屬性使用不同的默認(rèn)值。
HTML 4.01 與 HTML 5 之間的差異
HTML 5 中的新屬性:autofocus, form, formaction, formenctype, formmethod, formnovalidate 以及 formtarget。
提示和注釋
注釋:如果在 HTML 表單中使用 button 元素,不同的瀏覽器會提交不同的按鈕值。請使用 input 元素在 HTML 表單中創(chuàng)建按鈕。
屬性
new : HTML5 中的新屬性。
屬性 | 值 | 描述 |
---|---|---|
autofocus | autofocus | 規(guī)定當(dāng)頁面加載時按鈕應(yīng)當(dāng)自動地獲得焦點。 |
disabled | disabled | 規(guī)定應(yīng)該禁用該按鈕。 |
form | form_name | 規(guī)定按鈕屬于一個或多個表單。 |
formaction | url |
覆蓋 form 元素的 action 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formenctype | 見注釋 |
覆蓋 form 元素的 enctype 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formmethod |
|
覆蓋 form 元素的 method 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formnovalidate | formnovalidate |
覆蓋 form 元素的 novalidate 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
formtarget |
|
覆蓋 form 元素的 target 屬性。 注釋:該屬性與 type="submit" 配合使用。 |
name | button_name | 規(guī)定按鈕的名稱。 |
type |
|
規(guī)定按鈕的類型。 |
value | text | 規(guī)定按鈕的初始值。可由腳本進行修改。 |
注釋:formenctype 屬性可能的值:
- application/x-www-form-urlencoded
- multipart/form-data
- text/plain
全局屬性
<button> 標(biāo)簽支持 HTML 5 中的全局屬性。
事件屬性
<button> 標(biāo)簽支持 HTML 5 中的事件屬性。