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
Release: 2018-10-10 16:06:12
forward
2538 people have browsed it

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>
Copy after login

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

For more related tutorials, please visit JavaScript Video Tutorial

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template