HTMLFormElement.reportValidity()

翻译不完整。 请帮助我们翻译这篇文章!

方法 HTMLFormElement.reportValidity() 返回布尔值,如果form表单的子表单控件满足验证限制条件,则该方法返回 true ,否则返回false。当返回 false 时, 每个不合法的子控件的 invalid 事件将会被触发,并且验证中存在的问题会报告该用户。 

Syntax

HTMLFormElement.reportValidity()

Return value

布尔

Example

document.forms['myform'].addEventListener('invalid', function() {
  // Optional response here
}, false);

document.forms['myform'].addEventListener('submit', function() {
  document.forms['myform'].reportValidity();
}, false);

Specifications

Specification Status Comment
HTML Living Standard
HTMLFormElement.reportValidity()
Living Standard
HTML 5.1
HTMLFormElement.reportValidity()
Recommendation Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
reportValidityChrome Full support 40Edge Full support 17Firefox Full support 49IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 40Chrome Android Full support 40Firefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 4.0

Legend

Full support  
Full support
No support  
No support