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

HTMLSelectElement.setCustomValidity() 方法设置指定的验证消息为选择元素的自定义验证消息。

使用空字符串来表示该元素没有自定义的验证错误。

语法

selectElt.setCustomValidity(string);

Parameters

Specifications

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

浏览器兼容性

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

查看更多