EN
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

validity property

Returns a ValidityState object that represents the validity states of an element.

This property is read-only.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 4.10.21.3

Syntax

JavaScript
oValidityState = object.validity

Property values

Type: ValidityState

ValidityState object.

Standards information

Remarks

The following example displays all attributes in the ValidityState object.

Note  For more code samples, see Form controls part 1 and Form controls part 2: validation on the a Windows Store app using JavaScript sample site.

Examples


<!DOCTYPE html >
<html>
<head>
    <title>Valid states example</title>
    <script type="text/javascript">
        function getState() {
            var oState = document.getElementById("myField");
            var myState = oState.validity;
            var display = document.getElementById("showState");
            display.innerHTML = "";
            for (var t in myState) {
                display.innerHTML += (t + ": " + myState[t] + "<br/>");    //loop through attributes
            }
        }
    </script>
</head>
<body onload="getState();">
<h1>ValidState test</h1>
<div>The required text field only takes numbers between 4 and 20 in even increments. <br /><br />
Try different numbers to see how the validityState attributes react.</div>
<br />
<div><label>Enter a number from 4 to 20: 
<input id="myField" type="number" required  min="4" max ="20" step="2" />
<button onclick="getState();">Check state</button></label></div>

<div id="showState"></div>

</body>
</html>


See also

HTMLButtonElement
HTMLFieldSetElement
HTMLInputElement
HTMLObjectElement
HTMLSelectElement
HTMLTextAreaElement
ValidityState

 

 

Anzeigen:
© 2014 Microsoft