<button> 标签用于创建一个按钮,用户可以点击该按钮执行特定的操作或触发特定的事件。
属性
disabled: 指定按钮是否被禁用form: 指定按钮所属的表单formaction: 指定按钮点击后跳转的 URLformenctype: 指定表单数据的编码类型formmethod: 指定表单提交时使用的 HTTP 方法formnovalidate: 指定点击按钮时是否不执行表单验证formtarget: 指定表单提交时打开的目标窗口name: 指定按钮的名称type: 指定按钮的类型,可选值包括 "button", "submit", "reset"value: 指定按钮的值
示例代码
<button>点击我</button> <button type="submit">提交</button> <button type="reset">重置</button> <button disabled>禁用按钮</button> <button form="myForm">提交表单</button> <button formaction="/submit" formmethod="post">提交到指定 URL</button> <button name="btn">按钮名称</button> <button value="1">按钮值</button>
<button> 标签可以和 JavaScript 搭配使用,实现更加丰富的交互效果。
| 属性 | 值 | 描述 |
|---|---|---|
| autofocus | autofocus | 规定当页面加载时按钮应当自动地获得焦点。 |
| disabled | disabled | 规定应该禁用该按钮。 |
| form | form_id | 规定按钮属于一个或多个表单。 |
| formaction | URL | 规定当提交表单时向何处发送表单数据。覆盖 form 元素的 action 属性。该属性与 type="submit" 配合使用。 |
| formenctype | application/x-www-form-urlencoded multipart/form-data text/plain | 规定在向服务器发送表单数据之前如何对其进行编码。覆盖 form 元素的 enctype 属性。该属性与 type="submit" 配合使用。 |
| formmethod | getpost | 规定用于发送表单数据的 HTTP 方法。覆盖 form 元素的 method 属性。该属性与 type="submit" 配合使用。 |
| formnovalidate | formnovalidate | 如果使用该属性,则提交表单时不进行验证。覆盖 form 元素的 novalidate 属性。该属性与 type="submit" 配合使用。 |
| formtarget | _blank _self _parent _top framename | 规定在何处打开 action URL。覆盖 form 元素的 target 属性。该属性与 type="submit" 配合使用。 |
| name | name | 规定按钮的名称。 |
| type | button reset submit | 规定按钮的类型。 |
| value | text | 规定按钮的初始值。可由脚本进行修改。 |