javascript - How does js determine that the input value is a number, not less than or equal to 0, without using alert, but using red font on the same line to prompt the user
世界只因有你
2017-06-28 09:27:53
How does js determine that the input value is a number, not less than or equal to 0, and can be a decimal. If the conditions are not met, will prompt the user with red words
after %, TKS!
Determine whether the focus is within the input (or pass the focus leave event)
Then pass the value to the js method class for judgment. Judge according to your requirements
CSS:
HTML:
Javascript:
Short answer for mobile phones, add the pattern attribute to the input, use regularity to verify the content, and then use
input:invalid
in the css to mark the illegal content in the input in red (just a red box with red text or something), and the red text behind it will prompt p. Write with input, then useAfter setting up such rules, it should be almost the same (if the label is replaced with the ID, I won’t have to code more on my phone). However, if you need to be compatible with IE9, you may need to write another compatible one...
Reference:
MDN - Form Validation