无效
event fires when a submittable element has been checked for validity and doesn't satisfy its constraints.
| 冒泡 | No |
|---|---|
| 可取消 | Yes |
| 接口 |
事件
|
| 事件处理程序特性 |
GlobalEventHandlers.oninvalid
|
This event can be useful for displaying a summary of the problems with a form on submission. When a form is submitted,
无效
events are fired at each form control that is invalid. The validity of submittable elements is checked before submitting their owner
<form>
, or after the
checkValidity()
method of the element or its owner
<form>
被调用。
It is not checked on
blur
.
If a form is submitted with an invalid value, the submittable elements are checked and, if an error is found, the
无效
event will fire on the
无效
element. In this example, when an invalid event fires because of an invalid value in the input, the invalid value is logged.
<form action="#">
<ul>
<li><label>Enter an integer between 1 and 10: <input type="number" min="1" max="10" required></label></li>
<li><input type="submit" value="submit"></li>
</ul>
</form><p id="log"></p>
const input = document.querySelector('input')
const log = document.getElementById('log')
input.addEventListener('invalid', logValue)
function logValue(e) {
log.textContent += e.target.value
}
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
无效
event
|
Chrome 10 | Edge 12 | Firefox 4 | IE 10 | Opera 10 | Safari 5 | WebView Android 4 | Chrome Android 18 | Firefox Android 64 | Opera Android 12 | Safari iOS 5 | Samsung Internet Android 4.0 |
完整支持