判断鼠标的点击了那个键

window.onload = function () {
        var menu = document.getElementById("right_button_menu");
        document.oncontextmenu = function (e) {
            return false;
        }
        function click(e) {
            var e=e||event;
            if (e.which == 2||e.button==4){//中间滚轮键
                hide_menu(menu);
                return false;
            }
            else if(e.which==3||e.button==2) { //右键
                x = e.clientX;y=e.clientY;
                var l = document.body.scrollLeft>0?document.body.scrollLeft:document.documentElement.scrollLeft;
                var t = document.body.scrollTop>0?document.body.scrollTop:document.documentElement.scrollTop;
                document.title = "x"+(x+l) + "y" + (y+t);
                show_menu(menu,x+l,y+t);
            }
            else if(e.which==1||e.button==1){  //左键
                setTimeout(function () {
                    hide_menu(menu)
                },100)
            }
        }
        document.onmousedown = click;
        function show_menu(obj,left,top) {
            obj.style.left = left + "px";
            obj.style.top = top + "px";
            obj.style.display = 'block';

        }
        function hide_menu(obj) {
            obj.style.display='none';
        }
    }

  

posted @ 2016-08-07 21:14  快乐~  阅读(479)  评论(0编辑  收藏  举报