Mouse Right-click event

Source: Internet
Author: User

The left mouse Click event is what we often encounter, then, how to write a mouse right click event?

Usually, the mouse has three keys: Left (1), Middle key (2), right (3), jquery through E.which can determine which button clicked, if not through E.which judgment, the default click the left mouse button. For example:

$ ('. Btn '). MouseDown (function (e) {    if (3 = = E.which) {        alert (' This is a right-click event ');    } else if (1 = = E.which) {        alert (' This is a left-click event '),    } else{        alert (' This is a middle-click event ');}    )

The browser will have a default right mouse button event: Pop Up a menu bar (bad, just press the shortcut key, the menu disappears ...) At this point, if you want to pop up our custom menu bar, we'll block the default right-click event.

$ (document). Ready (function () {    $ (document). Unbind ("ContextMenu"). Bind ("ContextMenu", function (e) {        return false;    }); If you want to restore the mouse right-click event, simply change the return false to true.

Mouse Right-click event

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.