blob: 96de470bf2c935ee08f1e4a1a8a80a9731b127d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
---
title: HTMLFormElement.reportValidity()
slug: Web/API/HTMLFormElement/reportValidity
translation_of: Web/API/HTMLFormElement/reportValidity
---
<div>{{APIRef("HTML DOM")}}</div>
<p>方法 <strong><code>HTMLFormElement.reportValidity()</code></strong> 返回布尔值,如果form表单的子表单控件满足验证限制条件,则该方法返回 <code>true</code> ,否则返回<code>false</code>。当返回 <code>false</code> 时, 每个不合法的子控件的 <code><a href="https://developer.mozilla.org/en-US/docs/Web/Events/invalid">invalid</a></code> 事件将会被触发,并且验证中存在的问题会报告该用户。 </p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox"><em>HTMLFormElement</em>.reportValidity()
</pre>
<h3 id="Return_value">Return value</h3>
<p>{{domxref("布尔")}}</p>
<h2 id="Example">Example</h2>
<pre class="brush: js">document.forms['myform'].addEventListener('invalid', function() {
// Optional response here
}, false);
document.forms['myform'].addEventListener('submit', function() {
document.forms['myform'].reportValidity();
}, false);</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("HTML WHATWG", "forms.html#dom-cva-reportvalidity", "HTMLFormElement.reportValidity()")}}</td>
<td>{{Spec2("HTML WHATWG")}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName("HTML5.1", "semantics.html#the-constraint-validation-api", "HTMLFormElement.reportValidity()")}}</td>
<td>{{Spec2("HTML5.1")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.HTMLFormElement.reportValidity")}}</p>
|