Jquery event mechanism extension jquery right-click event _ jquery-js tutorial

Source: Internet
Author: User
Jquery's event mechanism is actually perfect, including clicking, double-clicking, moving the mouse in, and moving the mouse out. However, one event is missing. That is, right-click the event. Of course, you can also directly listen to the mouse and press the event, and then use if to judge and execute the corresponding function. The effect of the right-click event is caused by the slow development of technology and the lack of high-handed features. You can only rely on yourself, so you want to exercise yourself like a WEBQQ. It is best to prepare the necessary items before doing so. Jquery's event mechanism is actually perfect, including clicking, double-clicking, moving the mouse in, and moving the mouse out. However, one event is missing. That is, right-click the event. Of course, you can also directly listen to the mouse and press the event, and then use if to judge and execute the corresponding function. Results In a right-click event.

But this is not what I want. What I want seems to be that this event can be the same as other events, such as click events. It can be used conveniently without being judged every time. Here, you can use $ (). rightClick (); directly by writing the jquery extension.

JQuery plug-ins are mainly divided into three types

1. Plug-ins that encapsulate object Methods

(This plug-in encapsulates the object and is used to operate the object obtained through the selector, that is, the method needed here)

2. Plug-ins that encapsulate global functions

(Independent functions can be added to the namespace of jquery)

3. selector plug-in

(Although jquery's selector is very powerful, it still needs to expand some of its favorite selectors)

For other plug-ins, you can view related information on your own. Here we will start talking about it directly.

Here is the first plug-in type to be used. First, analyze the specific compiling ideas.

1. After you right-click an event, all system context menu functions are disabled.

2. After you bind a right-click event, the mouse is actually triggered.

3. Use if to judge whether the parameter is executed. if you right-click the parameter, the parameter can only be a function. If it is not a right-click operation, it is not executed.

I believe that I am familiar with jquery and understand how to do it.

Jquery event mechanism extension, jquery right-click the event.

The Code is as follows:


/* Right-click the plug-in */
(Function ($ ){
$. Fn. extend ({
// Define the right-click method to receive a function parameter
"RightClick": function (fn ){
// After this method is called, the system's right-click menu will be disabled
$ (Document). bind ('textmenu ', function (e ){
Return false;
});
// Bind the mouse button for this object
$ (This). mousedown (function (e ){
// If the right-click button is pressed, the function is executed.
If (3 = e. which ){
Fn ();
}
});
}
});

}) (JQuery );


The Code is as follows:


$ (Document). ready (function (e ){
$ ("Body"). rightClick (function () (alert ("right-click ")));
});


Jquery event mechanism extension, jquery right-click the event.
Same as other events
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.