--- title: HTMLSelectElement.checkValidity() slug: Web/API/HTMLSelectElement/checkValidity translation_of: Web/API/HTMLSelectElement/checkValidity ---
{{ APIRef("HTML DOM") }}

HTMLSelectElement.checkValidity() 方法會檢查元素是否有任何的檢核、驗證條件,並且檢查是否滿足這些條件。如果元素沒有通過這些檢核,瀏覽器會於該元素上觸發一個可取消的 {{event("invalid")}} 事件,並回傳 false

語法

var result = selectElt.checkValidity();

規範

Specification Status Comment
{{SpecName('HTML WHATWG', '#dom-cva-checkvalidity', 'HTMLSelectElement.checkValidity()')}} {{Spec2('HTML WHATWG')}} No change since the latest snapshot, {{SpecName('HTML5 W3C')}}.
{{SpecName('HTML5 W3C', 'forms.html#dom-cva-checkvalidity', 'HTMLSelectElement.checkValidity()')}} {{Spec2('HTML5 W3C')}} Initial definition, snapshot of {{SpecName('HTML WHATWG')}}

瀏覽器相容性

{{CompatibilityTable}}
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoDesktop(2.0)}} 10 {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Chrome Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile(2.0)}} 1.0 {{CompatUnknown}} {{CompatUnknown}} {{CompatVersionUnknown}}

參見