type属性指定按钮的类型,请不要忘记为按钮指定 type 属性。Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "submit"。
在线示例
两个按钮元素分别充当一个提交按钮和一个重置按钮(在表单中):
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML <button> type 属性使用-大卫编程网(div.cn)</title> </head> <body> <form action="action_page.php" method="get"> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <button type="submit" value="Submit">提交</button> <button type="reset" value="Reset">重置</button> </form> </body> </html>测试看看 ‹/›
浏览器兼容性
IEFirefoxOperaChromeSafari
所有主流浏览器都支持 type 属性。
定义和用法
type 属性规定按钮的类型。
提示: 请不要忘记为按钮指定 type 属性。Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "submit"。
HTML 4.01 与 HTML5之间的差异
没有.
语法
<button type="button|submit|reset">
属性值
值 | 描述 |
---|---|
submit | 该按钮是提交按钮(除了 Internet Explorer,该值是其他浏览器的默认值)。 |
button | 该按钮是可点击的按钮(Internet Explorer 的默认值)。 |
reset | 该按钮是重置按钮(清除表单数据)。 |