HTMLFormElement.reportValidity()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since December 2018.
方法 HTMLFormElement.reportValidity()
返回布尔值,如果 form 表单的子表单控件满足验证限制条件,则该方法返回 true
,否则返回false
。当返回 false
时,每个不合法的子控件的 invalid
事件将会被触发,并且验证中存在的问题会报告该用户。
Syntax
HTMLFormElement.reportValidity()
Return value
Example
js
document.forms["myform"].addEventListener(
"invalid",
function () {
// Optional response here
},
false,
);
document.forms["myform"].addEventListener(
"submit",
function () {
document.forms["myform"].reportValidity();
},
false,
);
Specifications
Specification |
---|
HTML # dom-cva-reportvalidity-dev |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
reportValidity |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.