Home>

What does jquery form validation need to do,Do you know In fact, it is very simple to complete the form verification as long as you do four things,Want to know which four things,Please read the following carefully.

First, a blur event occurs when an element loses focus.

Example:jquery blur () method

Add a 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 usageThe blur event occurs when the element loses focus.

The blur () method triggers a blur event or specifies a function to run when a blur event occurs.

prompt:This method is often used with the focus () method.

grammarTrigger the blur event for the selected element:

$(selector) .blur ()

Add a function to the blur event:

$(selector) .blur (function)

Second, when the input box gets focus,Triggered event.

Example:jquery focus () method

Add a 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 the element gains focus (either when the element is selected by mouse click or when the element is positioned by the tab key).

The focus () method fires the focus event or specifies a function to run when the focus event occurs.

prompt:This method is usually used in conjunction with the blur () method.

grammar

Trigger the focus event of the selected element:

$(selector) .focus ()

Add function to focus event:

$(selector) .focus (function)

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

Sequence of events related to keyup events:

keydown-the process of key down keypress-key was pressed keyup-key is released

The keyup event occurs when the keyboard key is released.

The keyup () method triggers a keyup event, or specifies a function to run when a keyup event occurs.

Tip:Use the event.which property to return which key was pressed.

grammar

Trigger the keyup event of the selected element:

$(selector) .keyup ()

Add function to keyup event:

$(selector) .keyup (function)

Fourth, the event that is triggered when the form is submitted

Example:jquerysubmit () method

When submitting the form,Show warning box:

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

Definition and usage

When submitting the form,The submit event occurs.

This event applies only to the

element.

The submit () method triggers the submit event or specifies a function to run when the submit event occurs.

grammarTrigger the submit event of the selected element:

$(selector) .submit ()

Add a function to the submit event:

$(selector) .submit (function)
  • Previous JavaScript code implementation prohibits right click, select, paste, shift, ctrl, alt
  • Next Learn with me JavaScript prototypes, getPrototypeOf and __proto__