What does jquery form validation need to do

  • 2020-11-18 05:15:41
  • OfStack

1. An blur event occurs when an element loses focus.

Example: the jQuery blur() method
Add functions to the blur event. when < input > blur event occurs when a field loses focus:


$("input").blur(function(){
alert("This input field has lost its focus.");
});

Definition and usage
An blur event occurs when an element loses focus.
The blur() method triggers the blur event, or specifies the function to run when an blur event occurs.
Tip: This method is often used with focus() method 1.
grammar
Triggers the blur event for the selected element:


$(selector).blur() 

Add functions to blur events:


$(selector).blur(function)

2. The event that is triggered when the input field gets focus.

Example: the jQuery focus() method
Add functions to focus events. when < input > focus event occurs when a field gets focus:


$("input").focus(function(){
$("span").css("display","inline").fadeOut(2000);
});

Definition and usage
The focus event occurs when the element is in focus (when the element is selected by mouse click or when the element is located via the tab key).
The focus() method triggers the focus event, or specifies the function to run when an focus event occurs.
Tip: This method is usually used with blur() method 1.
grammar
Triggers the focus event of the selected element:


$(selector).focus()

Add functions to focus events:


$(selector).focus(function)

3. keyup occurs when the keyboard keys are released

Example: the jQuery keyup() method
Settings when the keyboard keys are released < input > Field background color:


$("input").keyup(function(){
$("input").css("background-color","pink");
});

Definition and usage
Sequence of events related to keyup events:

keydown - The process of pressing the key The keypress - key is pressed The keyup - key is released

The keyup event occurs when the keyboard keys are released.
The keyup() method triggers the keyup event, or the function that specifies to run when an keyup event occurs.
Tip: Use the event.which attribute to return which key was pressed.
grammar
The keyup event that triggers the selected element:


$(selector).keyup() 

Add functions to keyup events:


$(selector).keyup(function)

4. Events that are triggered when the form is submitted

Example: jQuery submit() method
When the form is submitted, a warning box is displayed:


$("form").submit(function(){
alert("Submitted");
});

Definition and usage
The submit event occurs when the form is submitted.
This event applies only to < form > Elements.
The submit() method triggers an submit event, or a function that specifies to run when an submit event occurs.
grammar
The submit event that triggers the selected element:


$(selector).blur() 
0

Add functions to submit events:


$(selector).blur() 
1

These are the four things you need to do for jquery form validation. I hope you can study carefully and really master the skills of jquery form validation.


Related articles: