--- 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')}}

浏览器兼容性

{{Compat("api.HTMLSelectElement.setCustomValidity")}}

查看更多