JQuery Events
JQuery is specifically designed for event handling.
JQuery Event functions
The jquery event handling method is the core function in jquery.
The event handler refers to the method that is called when certain events occur in the HTML. The term "triggered" (or "fired") by an event is often used.
The JQuery code is usually put into the
Instance
$("button").click(function(){ $("p").hide(); }); });</script>
In the example above, a function is called when the button's Click event is triggered:
$ ("button"). Click (function () {: Some code ...} )
This method hides all <p> elements:
$ ("P"). Hide ();
Functions in a separate fileIf your site contains many pages, and you want your jquery function to be easy to maintain, put your jquery function in a separate. js file.
When we demonstrate jQuery in the tutorial, the function is added directly to the
InstanceJQuery Name conflictjquery uses the $ symbol as a way to profile jquery.
Functions in some other JavaScript libraries, such as Prototype, also use the $ notation.
JQuery uses a method called noconflict () to resolve the problem.
var jq=jquery.noconflict (), which helps you to use your own name (such as JQ) instead of the $ symbol.
1.
var jp=$.noconflict ();
JP (document). Ready (function () {
JP ("button"). Click (function () {
JP ("P"). Text ("JQuery is still running!") ");
2.
$.noconflict ();
jquery (document). Ready (function () {
jquery ("button"). Click (function () {
jquery ("P"). Text ("jquery is still running!") ");
Both of the above can be written, there may be more of the wording, I just wrote out their own test, MO!
JQuery Event MethodAn event method triggers an event that matches an element, or binds a function to an event of all matching elements.
Trigger instance:
$ ("Button#demo").click()
The example above will trigger the Click event of the button element id= "demo".
Binding instances:
$ ("Button#demo").click(function(){$("img").hide()})
The example above will hide all images when you click on the id= "demo" button.
Method |
Description |
Bind () |
Attaching one or more event handlers to a matching element |
Blur () |
Blur event that triggers, or binds a function to a specified element |
Change () |
The change event that triggers, or binds a function to a specified element |
Click () |
The Click event that triggers, or binds a function to a specified element |
DblClick () |
Double click event that triggers, or binds a function to a specified element |
Delegate () |
Attach one or more event handlers to the current or future child elements of a matching element |
Die () |
Removes all event handlers added through the live () function. |
Error () |
The error event that triggers, or binds a function to a specified element |
Event.isdefaultprevented () |
Returns whether Event.preventdefault () is called on the event object. |
Event.pagex |
The mouse position relative to the left edge of the document. |
Event.pagey |
The position of the mouse relative to the top edge of the document. |
Event.preventdefault () |
The default action for blocking events. |
Event.result |
Contains the last value returned by the event handler that is triggered by the specified event. |
Event.target |
The DOM element that triggered the event. |
Event.timestamp |
This property returns the number of milliseconds from January 1, 1970 to the time the event occurred. |
Event.type |
Describes the type of event. |
Event.which |
Indicates which key or button was pressed. |
Focus () |
A focus event that triggers, or binds a function to a specified element |
KeyDown () |
A key down event that triggers, or binds a function to a specified element |
KeyPress () |
Key press event that triggers, or binds a function to a specified element |
KeyUp () |
A key up event that triggers, or binds a function to a specified element |
Live () |
Add one or more event handlers for current or future matching elements |
Load () |
The load event that triggers, or binds a function to a specified element |
MouseDown () |
Mouse down event that triggers, or binds a function to a specified element |
MouseEnter () |
Mouse Enter event that triggers, or binds a function to a specified element |
MouseLeave () |
Mouse leave event that triggers, or binds a function to a specified element |
MouseMove () |
Mouse move event that triggers, or binds a function to a specified element |
Mouseout () |
Mouse out event that triggers, or binds a function to a specified element |
MouseOver () |
Mouse over event that triggers, or binds a function to a specified element |
MouseUp () |
Mouse up event that triggers, or binds a function to a specified element |
One () |
Adds an event handler to the matching element. The processor can only be triggered once per element. |
Ready () |
Document-Ready events (when the HTML document is ready to be available) |
Resize () |
Resize event that triggers, or binds a function to a specified element |
Scroll () |
Scroll event that triggers, or binds a function to a specified element |
Select () |
A select event that triggers, or binds a function to a specified element |
Submit () |
A submit event that triggers, or binds a function to a specified element |
Toggle () |
Binds two or more event handler functions that are executed when a rotating click event occurs. |
Trigger () |
Specified events for all matching elements |
Triggerhandler () |
The first specified event that is matched to an element |
Unbind () |
Removes an added event handler from the matching element |
Undelegate () |
Removes an added event handler from the matching element, now or in the future |
Unload () |
Unload event that triggers, or binds a function to a specified element |
Jqurey Study Notes---4, jQuery events