HTML <button> type 属性
实例
两个 button 元素,一个是提交按钮,另一个是重置按钮:
<form action="/action_page.php" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<button type="submit" value="提交">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
亲自试一试 »
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<button type="submit" value="提交">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
定义和用法
type 属性规定按钮的类型。
提示: 请始终为按钮规定 type 属性。Internet Explorer 的默认类型是 <button>,而其他浏览器中(包括 W3C 规范)的默认值是 <submit> 。
浏览器支持
属性 | |||||
---|---|---|---|---|---|
type | Yes | Yes | Yes | Yes | Yes |
语法
<button type="button|submit|reset">
属性值
值 | 描述 |
---|---|
button | 该按钮是可点击的按钮(Internet Explorer 的默认值)。 |
submit | 该按钮是提交按钮(除了 Internet Explorer,该值是其他浏览器的默认值)。 |
reset | 该按钮是重置按钮(清除重置表单数据)。 |