How to use the event event in jQuery
This article mainly shows you "how to use event events in jQuery". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to use event events in jQuery".
/ * = = Jquery event handling method = * /
1.pageX,pageY
Function: displays the location of the element (mouse pointer)
Syntax:
Event.pageX is equivalent to the left edge of a document.
Event.pageY is equivalent to the upper edge of a document
Example:
$(document) .mousemove (function (e) {
$("span") .text ("X:" + e.pageX + ", Y:" + e.pageY)
});
Displays the location of the mouse pointer
2.preventDefault
Function: prevent elements from default behavior, such as blocking submission when the form submit button is clicked
Syntax: event.preventDefault
Example:
$("a") .click (function (event) {
Event.preventDefault ()
});
Prevent Url connections from being opened
3.isDefaultPrevent
Function: returns whether the preventDefault method is called
Syntax: event.isDefaultPrevent
Example:
$("a") .click (function (event) {
Event.preventDefault ()
Alert ("Default prevented:" + event.isDefaultPrevented ())
});
Prevent links from opening URL and declare the results from isDefaultPrevented ()
4.result
Function: returns the last value returned by the event handler triggered by the specified event, unless this value is not defined
Syntax: event.result
Example:
$("button") .click (function (e) {
$("p") .html (e.result)
});
Displays the results of the last click event.
5.target
What it does: the attribute specifies which DOM element triggered the event.
Syntax: event.target
Example:
$("p, button, H2, h3") .click (function (event) {
("div") .html ("Triggered by a" + event.target.nodeName + "element.")
});
Shows which DOM element triggered the event
6.timeStamp
Function: returns the timestamp when the event is triggered
Syntax: event.timeStamp
$("button") .click (function (event) {
$("span") html (event.timeStamp)
});
Displays the timestamp when a click event on a button element occurs
7.type
Function: describe which event type to trigger
Syntax: event.type
Example:
$("p"). Bind ('click dblclick mouseover mouseout',function (event) {
("div") .html ("Event:" + event.type)
});
Shows which type of event was triggered
8.which
Function: displays which key or button has been pressed
Syntax: event.which
Example:
$("input") .keydown (function (event) {
("div") .html ("Key:" + event.which)
});
Show which key was pressed
The above is all the content of the article "how to use event events in jQuery". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!