This article mainly introduces jquery to implement simple form verification. The idea is to first add a required mark for each required and implement it using the each () method, if you are interested, you can refer to jquery's implementation of simple form verification. Let's first share with you the Implementation ideas.
General idea:
Add a required flag for each required.Each ()Method.
In the each () methodCreate an element,ThenAppend () methodAdd the created element to the end of the parent element.
HereThisEach time this corresponds to the corresponding input element, and then gets the corresponding parent element.
ThenInputElement addition loss focus event. Then, verify the user name and email.
Here we useJudge is ()If it is a user name, perform corresponding processing, and if it is an email, perform corresponding verification.
In the jQuery framework, you can also insert original javascript code. For exampleThis. value, and this. value. length.Determine the content.
Then, the email is verified andRegular Expression.
Then addKeyup eventAndFocus eventThat is, verification is also required during keyup. You can call the blur event. TriggerHandler () trigger is used to trigger the corresponding event.
At last, perform unified verification when submitting the form to handle the whole and details.
If required, addRed Star logo.
JQuery section: