HTMLButtonElement: setCustomValidity() 方法
setCustomValidity() 方法是 HTMLButtonElement 介面的一部分,用於為 <button> 元素設定自定義的有效性訊息。使用空字串表示該元素沒有自定義的有效性錯誤。
語法
js
setCustomValidity(string)
引數
string-
包含錯誤訊息的字串。空字串會移除任何自定義有效性錯誤。
返回值
無(undefined)。
示例
js
const errorButton = document.getElementById("checkErrors");
const errors = issuesToReport();
if (errors) {
errorButton.setCustomValidity("There is an error");
} else {
errorButton.setCustomValidity("");
}
規範
| 規範 |
|---|
| HTML # dom-cva-setcustomvalidity-dev |
瀏覽器相容性
載入中…