ValidityState
interface represents the
validity states
that an element can be in, with respect to constraint validation. Together, they help explain why an element's value fails to validate, if it's not valid.
For each of these Boolean properties, a value of
true
indicates that the specified reason validation may have failed is true, with the exception of the
valid
property, which is
true
if the element's value obeys all constraints.
badInput
只读
布尔
也就是
true
if the user has provided input that the browser is unable to convert.
customError
只读
布尔
indicating whether the element's custom validity message has been set to a non-empty string by calling the element's
setCustomValidity()
方法。
patternMismatch
只读
布尔
也就是
true
if the value does not match the specified
pattern
,和
false
if it does match. If true, the element matches the
:invalid
CSS pseudo-class.
rangeOverflow
只读
布尔
that is true if the value is greater than the maximum specified by the
max
attribute, or
false
if it is less than or equal to the maximum. If true, the element matches the
:invalid
and
:out-of-range
and CSS pseudo-classes.
rangeUnderflow
只读
布尔
也就是
true
if the value is less than the minimum specified by the
min
attribute, or
false
if it is greater than or equal to the minimum. If true, the element matches the
:invalid
and
:out-of-range
CSS pseudo-classes.
stepMismatch
只读
布尔
也就是
true
if the value does not fit the rules determined by the
step
attribute (that is, it's not evenly divisible by the step value), or
false
if it does fit the step rule. If true, the element matches the
:invalid
and
:out-of-range
CSS pseudo-classes.
tooLong
只读
布尔
也就是
true
if the value exceeds the specified
maxlength
for
HTMLInputElement
or
HTMLTextAreaElement
objects, or false if its length is less than or equal to the maximum length.
注意:
This property is never
true
in Gecko, because elements' values are prevented from being longer than
maxlength
.
If true, the element matches the the
:invalid
and
:out-of-range
CSS pseudo-classes.
tooShort
只读
布尔
也就是
true
if the value fails to meet the specified
minlength
for
HTMLInputElement
or
HTMLTextAreaElement
对象,或
false
if its length is greater than or equal to the minimum length. If true, the element matches the
:invalid
and
:out-of-range
CSS pseudo-classes.
typeMismatch
只读
布尔
也就是
true
if the value is not in the required syntax (when
type
is
email
or
url
),或
false
if the syntax is correct. If true, the element matches the
:invalid
CSS pseudo-class.
valid
只读
布尔
也就是
true
if the element meets all its validation constraints, and is therefore considered to be valid, or
false
if it fails any constraint. If true, the element matches the
:valid
CSS pseudo-class; the
:invalid
CSS pseudo-class otherwise.
valueMissing
只读
布尔
也就是
true
if the element has a
required
attribute, but no value, or
false
otherwise. If true, the element matches the
:invalid
CSS pseudo-class.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'ValidityState' in that specification. |
实时标准 | 实时标准 |
|
HTML 5.1
The definition of 'ValidityState' in that specification. |
推荐 | No change from the previous snapshot HTML5 . |
|
HTML5
The definition of 'ValidityState' in that specification. |
推荐 | First snapshot of HTML 实时标准 containing this interface. |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ValidityState
|
Chrome 15 | Edge 12 | Firefox 4 | IE 10 | Opera 12.1 | Safari 11 | WebView Android 4 | Chrome Android Yes | Firefox Android 64 | Opera Android 12.1 | Safari iOS 5 | Samsung Internet Android Yes |
badInput
|
Chrome 25 | Edge 14 | Firefox 29 | IE No | Opera 15 | Safari 11 | WebView Android 4.4 | Chrome Android Yes | Firefox Android 64 | Opera Android 14 | Safari iOS 7 | Samsung Internet Android Yes |
tooLong
|
Chrome 15 |
Edge
12
|
Firefox
4
|
IE 10 | Opera 15 | Safari 11 | WebView Android 4 | Chrome Android Yes | Firefox Android 64 | Opera Android 14 | Safari iOS 5 | Samsung Internet Android Yes |
tooShort
|
Chrome 40 | Edge 17 | Firefox 51 | IE No | Opera 27 | Safari 11 | WebView Android 67 | Chrome Android Yes | Firefox Android 64 | Opera Android 27 | Safari iOS 10 | Samsung Internet Android Yes |
完整支持
不支持
见实现注意事项。
ValidityState
BeforeUnloadEvent
DOMStringMap
ErrorEvent
GlobalEventHandlers
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDialogElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLInputElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMediaElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
Navigator
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
Window
WindowBase64
WindowEventHandlers
WindowTimers