在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 關(guān)于在網(wǎng)頁(yè)自定義鼠標(biāo)右鍵菜單的問題

關(guān)于在網(wǎng)頁(yè)自定義鼠標(biāo)右鍵菜單的問題

如果我要做出在網(wǎng)頁(yè)中選中一段文字,鼠標(biāo)右鍵出現(xiàn)我自定義的菜單,有什么思路可以實(shí)現(xiàn)。

回答
編輯回答
寫榮
  1. 提取選中文本 Demo

  2. jQuery的context menu

2017年9月13日 02:02
編輯回答
舊螢火

js部分///
$(function() {

    $.contextMenu({
        selector: '.context-menu-one', 
        callback: function(key, options) {
            var m = "clicked: " + key;
            window.console && console.log(m) || alert(m); 
        },
        items: {
            "edit": {name: "Edit", icon: "edit"},
            "cut": {name: "Cut", icon: "cut"},
           copy: {name: "Copy", icon: "copy"},
            "paste": {name: "Paste", icon: "paste"},
            "delete": {name: "Delete", icon: "delete"},
            "sep1": "---------",
            "quit": {name: "Quit", icon: function(){
                return 'context-menu-icon context-menu-icon-quit';
            }}
        }
    });

    $('.context-menu-one').on('click', function(e){
        console.log('clicked', this);
    })    
});


html 部分///

<span class="context-menu-one btn btn-neutral">right click me</span>   如果想整個(gè)頁(yè)面 直接body添加
2017年5月4日 19:30
編輯回答
她愚我

監(jiān)聽document的oncontextmenu事件
具體代碼參考

document.oncontextmenu=function(event){//這是實(shí)現(xiàn)的關(guān)鍵點(diǎn) 
var event=event||window.event;//這個(gè)都不是問題了吧 
forRight.style.display="block"; 
forRight.style.left=event.clientX+"px"; 
forRight.style.top=event.clientY+"px";//鼠標(biāo)的坐標(biāo)啊 
return false;//這里返回false就是為了屏蔽默認(rèn)事件 
}; 
2018年8月19日 20:12