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.
Copy codeThe Code is as follows:/* Right-click 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 );