Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
HTMLSelectElement 介面的 checkValidity() 方法會回傳一個表示此元素是否符合任何套用於其上的約束驗證規則的布林值。如果為 false,此方法也會在該元素上觸發一個 invalid 事件。因為 checkValidity() 沒有預設的瀏覽器行為,取消此 invalid 事件不會有任何效果。
備註:具有非 null validationMessage 的 HTML <select> 元素會被視為無效,且會匹配 CSS :invalid 偽類,並導致 checkValidity() 回傳 false。使用 HTMLSelectElement.setCustomValidity() 方法將 HTMLSelectElement.validationMessage 設定為空字串,以將 validity 狀態設定為有效。
無。
若元素的數值沒有有效性問題,則回傳 true;否則回傳 false。
在下列範例中,呼叫 checkValidity() 會回傳 true 或 false。
| HTML # dom-cva-checkvalidity-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2026年1月5日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.