HTML DOM
The validity read-only property of the HTMLSelectElement interface returns a ValidityState object that represents the validity states this element is in.
Value
A ValidityState object.
Example
The following example gets the validity state of a select element and processes it if it is not valid:
const select = document.getElementById("mySelect");
const validityState = select.validity;
if (!validityState.valid) {
// Test each validity state
}
Specifications
Browser compatibility
See also
- HTMLSelectElement.checkValidity()
- select
- form
- Learn: Client-side form validation
- Guide: Constraint validation
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
