A Blur event occurs when the element loses focus.
Example: JQuery blur () method
Add function to blur event. Blur event occurs when <input> field loses focus:
$ ("input"). blur (function () {
alert ("This input field has lost it focus.");
});
Definitions and usage
The Blur event occurs when the element loses focus.
The blur () method triggers the Blur event, or a function that runs when the blur event occurs.
Tip: This method is often used in conjunction with the focus () method.
Grammar
to trigger the Blur event for the selected element:
Add function to blur event:
$ (selector). blur (function)
The event that triggers when the input box gets the focus.
Example: JQuery focus () method
Add function to focus event. Focus event occurs when the <input> field is focused:
$ ("input"). focus (function () {
$ ("span"). CSS ("display", "inline"). fadeout;
Definitions and usage
The focus event occurs when the element is focused (when the selected element is clicked through the mouse or when the element is positioned through the TAB key).
The focus () method triggers the focus event, or the function that runs when the focus event occurs.
Tip: This method is usually used in conjunction with the blur () method.
Grammar
Focus event that triggers the selected element:
Add function to focus event:
$ (selector). focus (function)
Third, the KeyUp event occurs when the keyboard key is released
Example: JQuery KeyUp () method
When the keyboard key is loosened, set the background color of the <input> field:
$ ("input"). KeyUp (function () {
$ ("input"). CSS ("Background-color", "pink");
Definitions and usage
Sequence of events related to the KeyUp event:
- KeyDown-Key Press process
- KeyPress-the key is pressed
- KeyUp-Key is loosened
The KeyUp event occurs when the keyboard key is released.
The KeyUp () method triggers the KeyUp event, or a function that runs when the KeyUp event occurs.
Tip: Please use the Event.which property to return which key is pressed.
Grammar
KeyUp event that triggers the selected element:
Add function to KeyUp event:
$ (selector). KeyUp (function)
Iv. events that are triggered when the form is submitted
Example: JQuery Submit () method
When submitting a form, a warning box is displayed:
$ ("form"). Submit (function () {
alert ("submitted");
});
Definitions and usage
The Submit event occurs when the form is submitted.
This event applies only to <form> elements.
The submit () method triggers a Submit event, or a function that runs when a submit event occurs.
Grammar
to trigger a submit event for the selected element:
Add function to submit event:
$ (selector). Submit (function)
That's the four things you need to do with jquery form validation, and hopefully you'll have a good look at the techniques of jquery form validation.