HTML <button> type 属性
定义和用法
type
属性规定按钮的类型。
提示:请始终为 <button> 元素指定 type
属性。不同的浏览器可能对 <button> 元素使用不同的默认类型。
实例
两个按钮元素,一个充当提交按钮,另一个充当重置按钮(在表单中):
<form action="/action_page.php" method="get"> <label for="fname">名字:</label> <input type="text" id="fname" name="fname"><br><br> <label for="lname">姓氏:</label> <input type="text" id="lname" name="lname"><br><br> <button type="submit" value="提交">提交</button> <button type="reset" value="重置">重置</button> </form>
语法
<button type="button|submit|reset">
属性值
值 | 描述 |
---|---|
button | 该按钮是可点击的按钮。 |
submit | 该按钮是提交按钮(提交表单数据)。 |
reset | 该按钮是重置按钮(将表单数据重置为其初始值)。 |
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 支持 | 支持 | 支持 | 支持 |