jquery.contextMenu 鼠標右鍵

本文介紹一種網頁中實現右鍵功能的方案–contextMenu。

下載

下載地址
https://github.com/swisnl/jQuery-contextMenu

下載得到壓縮文件jQuery-contextMenu-master.zip

解壓後,使用dist目錄下css、js。

使用方法

使用步驟:

(1) 引用css、js。

(2) html、js代碼。

簡單例子如下:
代碼test.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<link href="libs/jQuery-contextMenu/dist/jquery.contextMenu.css" rel="stylesheet"/>

<script src="libs/jQuery/jquery-1.8.3.min.js"></script>
<script src="libs/jQuery-contextMenu/dist/jquery.contextMenu.js"></script>
</head>

<body>

<span class="context-menu-one btn btn-neutral">right click me</span>

<script>

    $(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);
        })    
    });

</script>

</body>
</html>

效果

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章