HTMLButtonElement: setCustomValidity() メソッド
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.
setCustomValidity()
は HTMLButtonElement
インターフェイスのメソッドで、
独自の検証メッセージを <button>
要素に設定します。空文字列を使用すると、要素に独自の検証エラーがないことを示します。
構文
js
setCustomValidity(string)
引数
string
-
エラーメッセージが入った文字列。空文字列を指定すると、独自の検証エラーがすべて除去されます。
返値
なし (undefined
)。
例
js
const errorButton = document.getElementById("checkErrors");
const errors = issuesToReport();
if (errors) {
errorButton.setCustomValidity("エラーがあります");
} else {
errorButton.setCustomValidity("");
}
仕様書
Specification |
---|
HTML # dom-cva-setcustomvalidity-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
setCustomValidity |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
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.