Home >Web Front-end >JS Tutorial >How to add mouse right click event in js

How to add mouse right click event in js

PHPz
PHPzforward
2016-05-16 19:16:402526browse

The right mouse click event is used in the project, just treat it as a few notes here

Just enter the code

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title></head><body>
    <button id = "btn1">点击我右击</button>
    <script type="text/javascript">
        //这一步是为了阻止右击时系统默认的弹出框
        document.getElementById("btn1").oncontextmenu = function(e){
            e.preventDefault();
        };        //在这里你就可以自己定义事件的函数啦
        document.getElementById("btn1").onmouseup=function(oEvent) {
            if (!oEvent) oEvent=window.event;            if (oEvent.button==2) {
                console.log(&#39;鼠标右击了&#39;)
            }
        }    </script></body></html>

That’s it, isn’t it very simple! ! ! !

For more related tutorials, please visit JavaScript Video Tutorial

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete
Previous article:A text editor code for QQ mailbox_javascript skillsNext article:A text editor code for QQ mailbox_javascript skills

Related articles

See more