<input>
elements of type
reset
are rendered as buttons, with a default
click
event handler that resets all of the inputs in the form to their initial values.
You should usually avoid including reset buttons in your forms. They're rarely useful, and are instead more likely to frustrate users who click them by mistake (often while trying to click the submit button ).
| 值 |
A
DOMString
used as the button's label
|
| 事件 |
click
|
| Supported common attributes |
type
and
value
|
| IDL attributes |
value
|
| 方法 | None |
An
<input type="reset">
元素的
value
attribute contains a
DOMString
that is used as the button's label. Buttons such as
reset
don't have a value otherwise.
<input type="reset" value="Reset the form">
If you don't specify a
value
, you get an button with the default label (typically "Reset," but this will vary depending on the
用户代理
):
<input type="reset">
<input type="reset">
buttons are used to reset forms. If you want to create a custom button and then customize the behaviour using JavaScript, you need to use
<input type="button">
, or better still, a
<button>
元素。
We'll begin by creating a simple reset button:
<form>
<div>
<label for="example">Type in some sample text</label>
<input id="example" type="text">
</div>
<div>
<input type="reset" value="Reset the form">
</div>
</form>
This renders like so:
Try entering some text into the text field, and then pressing the reset button.
To add a keyboard shortcut to a reset button — just as you would with any
<input>
for which it makes sense — you use the
accesskey
全局属性。
在此范例中,
r
is specified as the access key (you'll need to press
r
plus the particular modifier keys for your browser/OS combination; see
accesskey
for a useful list of those).
<form>
<div>
<label for="example">Type in some sample text</label>
<input id="example" type="text">
</div>
<div>
<input type="reset" value="Reset the form"
accesskey="r">
</div>
</form>
The problem with the above example is that there's no way for the user to know what the access key is! This is especially true since the modifiers are typically non-standard to avoid conflicts. When building a site, be sure to provide this information in a way that doesn't interfere with the site design (for example by providing an easily accessible link that points to information on what the site access keys are). Adding a tooltip to the button (using the
title
attribute) can also help, although it's not a complete solution for accessibility purposes.
To disable a reset button, simply specify the
被禁用
global attribute on it, like so:
<input type="reset" value="Disabled" disabled>
You can enable and disable buttons at run time by simply setting
被禁用
to
true
or
false
; in JavaScript this looks like
btn.disabled = true
or
btn.disabled = false
.
注意
: See the
<input type="button">
page for more ideas about enabling and disabling buttons.
Buttons don't participate in constraint validation; they have no real value to be constrained.
We've included simple examples above. There isn't really anything more to say about reset buttons.
| 规范 | 状态 |
|---|---|
|
HTML 实时标准
The definition of '<input type="reset">' in that specification. |
实时标准 |
|
HTML5
The definition of '<input type="reset">' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
type="reset"
|
Chrome 完整支持 1 | Edge 完整支持 12 |
Firefox
完整支持
1
注意事项
|
IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 1 | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes |
Firefox Android
完整支持
4
注意事项
|
Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
见实现注意事项。
<input>
和
HTMLInputElement
interface which implements it.
<button>
element
<button>
<datalist>
<fieldset>
<form>
<input>
<label>
<legend>
<meter>
<optgroup>
<option>
<output>
<progress>
<select>
<textarea>
<input>
类型
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">