3种不同的ContextMenu右键菜单演示

简单使用的右键菜单,希望能帮助大家。下面是截图和实例代码下载

3种不同的ContextMenu右键菜单演示_第1张图片
 

Java代码    收藏代码
  1. "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. "http://www.w3.org/1999/xhtml">  
  3.        
  4.         "Content-Type" content="text/html; charset=utf-8" />   
  5.         <span class="number">3</span><span style="color:#000000;">种不同的ContextMenu右键菜单演示  
  6.         "text/css">  
  7.             .content{margin:0 auto;width:360px;}  
  8.             .content p{margin:20px 0 0 0;border:solid 1px #C5D8FF;background:#EDF2FF;padding:10px;}  
  9.           
  10.       
  11.       
  12.   
  13.         class="container">  
  14.             class="demo">  
  15.                 class="contextMenu" id="myMenu1">  
  16.                     
        
    •                         "open">"/api/jq/ContextMenu/images/folder.png" /> Open
    •   
    •                         "email">"/api/jq/ContextMenu/images/email.png" /> Email
    •   
    •                         "save">"/api/jq/ContextMenu/images/disk.png" /> Save
    •   
    •                         "delete">"/api/jq/ContextMenu/images/cross.png" /> Delete
    •   
    •                     
      
  17.                 
  
  •   
  •                 class="contextMenu" id="myMenu2">  
  •                     
        
    •                         "item_1">Item 1
    •   
    •                         "item_2">Item 2
    •   
    •                         "item_3">Item 3
    •   
    •                         "item_4">Item 4
    •   
    •                         "item_5">Item 5
    •   
    •                         "item_6">Item 6
    •   
    •                         "item_7">Item 7
    •   
    •                         "item_8">Item 8
    •   
    •                     
      
  •                 
  •   
  •   
  •                 class="contextMenu" id="myMenu3">  
  •                     
        
    •                         "item_1">Item 1
    •   
    •                         "item_2">Item 2
    •   
    •                         "item_3">Item 3
    •   
    •                     
      
  •                 
  •   下载
  •                 class="content">  
  •                     class="demo1">演示 右键单击我的! !

      
  •                     class="demo2">在这个段落里面右键点击触发菜单

      
  •                     "font-weight: bold;">  
  •                         class="demo3" id="dontShow" style="padding: 5px; background-color:pink">不显示菜单  
  •                         class="demo3" id="showOne" style="padding: 5px;background-color:lightgreen">显示第一项  
  •                         class="demo3" id="showAll" style="padding: 5px;background-color:lightblue">全部显示  
  •                     

      
  •                 
  •   
  •             
  •   
  •         
  •   
  •         "text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.min.js">  
  •         "text/javascript" src="/api/jq/ContextMenu/js/jquery.contextmenu.r2.js">  
  •         "text/javascript">  
  •             $(document).ready(function() {  
  •                 //class为demo1的样式绑定此右键菜单  
  •                 $('.demo1').contextMenu('myMenu1', {  
  •                     bindings: { //绑定事件     
  •                         'open': function(t) {  
  •                             alert('Trigger was ' + t.id + '\nAction was Open');  
  •                         },  
  •                         'email': function(t) {  
  •                             alert('Trigger was ' + t.id + '\nAction was Email');  
  •                         },  
  •                         'save': function(t) {  
  •                             alert('Trigger was ' + t.id + '\nAction was Save');  
  •                         },  
  •                         'delete': function(t) {  
  •                             alert('Trigger was ' + t.id + '\nAction was Delete');  
  •                         }  
  •                     }  
  •                 });  
  •                 //class为demo2的样式绑定此右键菜单  
  •   
  •                 $('.demo2').contextMenu('myMenu2', {  
  •                     menuStyle: { //菜单样式  
  •                         border: '2px solid #000'  
  •                     },  
  •                     itemStyle: { //菜单项样式  
  •                         fontFamily: 'verdana',  
  •                         backgroundColor: '#666',  
  •                         color: 'white',  
  •                         border: 'none',  
  •                         padding: '1px'  
  •                     },  
  •                     itemHoverStyle: { //菜单项鼠标放在上面样式  
  •                         color: '#fff',  
  •                         backgroundColor: '#0f0',  
  •                         border: 'none'  
  •                     }  
  •                 });  
  •   
  •                 //class为demo3的样式绑定此右键菜单  
  •                 $('.demo3').contextMenu('myMenu3', {  
  •                     onContextMenu: function(e) { //重写onContextMenu  
  •                         if ($(e.target).attr('id') == 'dontShow')  
  •                             return false;  
  •                         else  
  •                             return true;  
  •                     },  
  •                     onShowMenu: function(e, menu) { //重写onShowMenu事件,单独对id=showOne设置  
  •                         if ($(e.target).attr('id') == 'showOne') {  
  •                             $('#item_2, #item_3', menu).remove();  
  •                         }  
  •                         return menu;  
  •                     }  
  •                 });  
  •             });  
  •           
  •       
  •  
  • 你可能感兴趣的:(3种不同的ContextMenu右键菜单演示)