ElementInternals: checkValidity() メソッド
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
checkValidity()
は ElementInternals
インタフェイスのメソッドで、要素が適用された制約検証のルールを満たしているかどうかをチェックします。
もし checkValidity
が false
を返したら、キャンセル可能な invalid イベントが要素で発生します。
構文
checkValidity()
引数
なし。
返値
論理値で、要素がすべての検証される制約に合格していれば true
を返します。
例外
NotSupportedError
DOMException
-
要素の
formAssociated
プロパティがtrue
に設定されていない場合に発生します。
例
以下の例では、 ElementInternals.setValidity()
を使用して、要素が検証ルールを満たしていないことを示します。 checkValidity()
を呼び出すと false
が返されます。再度 setValidity
を呼び出し、今度はすべてのルールが false になっていることを示すと、checkValidity()
は true
を返します。
let element = document.getElementById("join-checkbox");
element.internals_.setValidity({ valueMissing: true }, "メッセージ");
console.log(element.internals_.checkValidity()); // false
element.internals_.setValidity({});
console.log(element.internals_.checkValidity()); // true
仕様書
Specification |
---|
HTML # dom-elementinternals-checkvalidity |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
checkValidity |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support