1. A blur event occurs when the element loses focus.
Example: jQuery blur() method
Add function to the blur event. The blur event occurs when the <input> field loses focus:
$("input").blur(function(){ alert("This input field has lost its focus."); });
Definition and usage
The blur event occurs when the element loses focus.
The blur() method triggers the blur event, or specifies the function that runs when the blur event occurs.
hint:This method is often used with the focus() method.
grammar
Triggers the blur event for the selected element:
$(selector).blur()
Add function to the blur event:
$(selector).blur(function)
2. The event triggered when the input box obtains focus.
Example: jQuery focus() method
Add function to the focus event. The focus event occurs when the <input> field gets focus:
$("input").focus(function(){ $("span").css("display","inline").fadeOut(2000); });
Definition and usage
The focus event occurs when an element gains focus (when an element is selected by clicking the mouse or positioning an element through the tab key).
The focus() method triggers the focus event, or specifies the function that runs when the focus event occurs.
hint:This method is usually used with the blur() method.
grammar
Triggers the focus event of the selected element:
$(selector).focus()
Add function to focus event:
$(selector).focus(function)
3. Keyup event occurs when the keyboard key is released
Example: jQuery keyup() method
When the keyboard key is released, set the background color of the <input> field:
$("input").keyup(function(){ $("input").css("background-color","pink"); });
Definition and usage
The sequence of events related to keyup events:
- keydown - the process of key pressing
- keypress - key is pressed
- keyup - key is released
The keyup event occurs when the keyboard key is released.
The keyup() method triggers the keyup event, or specifies the function that runs when the keyup event occurs.
Tip: Please use the attribute to return which key was pressed.
grammar
Trigger keyup event of the selected element:
$(selector).keyup()
Add function to keyup event:
$(selector).keyup(function)
4. Events triggered when the form is submitted
Example: jQuerysubmit() method
When submitting a form, a warning box is displayed:
$("form").submit(function(){ alert("Submitted"); });
Definition and usage
The submit event occurs when the form is submitted.
This event only applies to <form> elements.
The submit() method triggers the submit event, or specifies the function that runs when the submit event occurs.
grammar
Trigger the submit event of the selected element:
$(selector).submit()
Add function to submit event:
$(selector).submit(function)
The above are four things that need to be done in jquery form verification. I hope everyone will study it carefully and truly master the skills of jquery form verification.