Last active
October 8, 2021 01:42
-
-
Save relyky/3ece4aad4c93eb5e3affb75d4edc4508 to your computer and use it in GitHub Desktop.
HTML, form validation event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// | |
| /// HTML原生的 validation | |
| /// ref→[Constraint validation interfaces](https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation#element.setcustomvalidity(message)) | |
| /// ref→[HTMLObjectElement.validationMessage](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage) | |
| /// ref→[HTMLObjectElement.validity](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity) | |
| /// ref→[validityState.badInput](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState/badInput) | |
| /// | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| </head> | |
| <body> | |
| <h1><a href="https://www.w3schools.com/tags/att_input_min.asp">The input min and max attributes</a></h1> | |
| <p>The min and max attributes specify the minimum and maximum values for an input element.</p> | |
| <form action="/action_page.php"> | |
| <label for="quantity">Quantity (between 1 and 5):</label> | |
| <input type="number" id="quantity" value="87" name="quantity" min="1" max="5"><br><br> | |
| <button type="submit">Send</button> | |
| </form> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
| <script> | |
| //input.addEventListener('invalid', logValue) | |
| $('#quantity').on('invalid',function(e){ | |
| console.log('#quantity.invalid', { | |
| validationMessage: e.target.validationMessage, | |
| validity:e.target.validity, | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment