HTML <button> 標籤
實例
以下代碼標記一個按鈕:
<button type="button">點我!</button>
流覽器支持
所有主流流覽器都支持 <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 中的新屬性。
屬性 | 值 | 描述 |
---|---|---|
autofocusNew | autofocus | 規定當頁面加載時按鈕應當自動地獲得焦點。 |
disabled | disabled | 規定應該禁用該按鈕。 |
formNew | form_id | 規定按鈕屬於一個或多個表單。 |
formactionNew | URL | 規定當提交表單時向何處發送表單數據。覆蓋 form 元素的 action 屬性。該屬性與 type="submit" 配合使用。 |
formenctypeNew | application/x-www-form-urlencoded multipart/form-data text/plain |
規定在向伺服器發送表單數據之前如何對其進行編碼。覆蓋 form 元素的 enctype 屬性。該屬性與 type="submit" 配合使用。 |
formmethodNew | get post |
規定用於發送表單數據的 HTTP 方法。覆蓋 form 元素的 method 屬性。該屬性與 type="submit" 配合使用。 |
formnovalidateNew | formnovalidate | 如果使用該屬性,則提交表單時不進行驗證。覆蓋 form 元素的 novalidate 屬性。該屬性與 type="submit" 配合使用。 |
formtargetNew | _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 對象