JQuery之ContextMenu(右键菜单)

插件下载地址: http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.js 压缩版: http://www.trendskitchens.co.nz/jquery/contextmenu/jquery.contextmenu.r2.packed.js
Jquery主页:   http://jquery.com/
插件中的参数说明:

JQuery之ContextMenu(右键菜单) Parameters JQuery之ContextMenu(右键菜单)menu_id JQuery之ContextMenu(右键菜单)The id of the menu as defined in your markup. You can bind one or more elements to a menu. Eg $("table td").contextMenu("myMenu") will bind the menu with id "myMenu" to all table cells. JQuery之ContextMenu(右键菜单)Note: This behaviour has changed from r1 where you needed a "#" before the id JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单)settings JQuery之ContextMenu(右键菜单)ContextMenu takes an optional settings object that lets you style your menu and bind click handlers to each option. ContextMenu supports the following properties in the settings object: JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单)bindings JQuery之ContextMenu(右键菜单)An object containing "id":function pairs. The supplied function is the action to be performed when the associated item is clicked. The element that triggered the current menu is passed to this handler as the first parameter. JQuery之ContextMenu(右键菜单)Note: This behaviour has changed from r1 where you needed a "#" before the id JQuery之ContextMenu(右键菜单)menuStyle JQuery之ContextMenu(右键菜单)An object containing styleName:value pairs for styling the containing < ul > menu. JQuery之ContextMenu(右键菜单)itemStyle JQuery之ContextMenu(右键菜单)An object containing styleName:value pairs for styling the < li > elements. JQuery之ContextMenu(右键菜单)itemHoverStyle JQuery之ContextMenu(右键菜单)An object containing styleName:value pairs for styling the hover behaviour of < li > elements. JQuery之ContextMenu(右键菜单)shadow JQuery之ContextMenu(右键菜单)Boolean: display a basic drop shadow on the menu. JQuery之ContextMenu(右键菜单)Defaults to true JQuery之ContextMenu(右键菜单)eventPosX JQuery之ContextMenu(右键菜单)Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientX". JQuery之ContextMenu(右键菜单)Defaults to: 'pageX' JQuery之ContextMenu(右键菜单)eventPosY JQuery之ContextMenu(右键菜单)Allows you to define which click event is used to determine where to place the menu. There are possibly times (particularly in IE6) where you will need to set this to "clientY". JQuery之ContextMenu(右键菜单)Defaults to: 'pageY' JQuery之ContextMenu(右键菜单)onContextMenu(event) JQuery之ContextMenu(右键菜单)A custom event function which runs before the context menu is displayed. If the function returns false the menu is not displayed. This allows you to attach the context menu to a large block element (or the entire document) and then filter on right click whether or not the context menu should be shown. JQuery之ContextMenu(右键菜单)onShowMenu(event, menu) JQuery之ContextMenu(右键菜单)A custom event function which runs before the menu is displayed. It is passed a reference to the menu element and allows you to manipulate the output before the menu is shown. This allows you to hide/show options or anything else you can think of before showing the context menu to the user. This function must return the menu. JQuery之ContextMenu(右键菜单)

通过此插件可以在不同的html元素内建立contextmenu,并且可以自定义样式.

JQuery之ContextMenu(右键菜单) < HTML > JQuery之ContextMenu(右键菜单) < HEAD > JQuery之ContextMenu(右键菜单)  < TITLE > JQuery右键菜单 </ TITLE > JQuery之ContextMenu(右键菜单)  < script  src ="jquery-1.2.6.min.js" ></ script > JQuery之ContextMenu(右键菜单)  < script src ="jquery.contextmenu.r2.js" ></ script > JQuery之ContextMenu(右键菜单) </ HEAD > JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单) < BODY > JQuery之ContextMenu(右键菜单) < span class ="demo1" style ="color:green;" > JQuery之ContextMenu(右键菜单)    右键点此 JQuery之ContextMenu(右键菜单) </ span > JQuery之ContextMenu(右键菜单) < hr /> JQuery之ContextMenu(右键菜单) < div id ="demo2" > JQuery之ContextMenu(右键菜单)    右键点此 JQuery之ContextMenu(右键菜单) </ div > JQuery之ContextMenu(右键菜单) < hr /> JQuery之ContextMenu(右键菜单) < div class ="demo3" id ="dontShow" > JQuery之ContextMenu(右键菜单)  不显示 JQuery之ContextMenu(右键菜单) </ div > JQuery之ContextMenu(右键菜单) < hr /> JQuery之ContextMenu(右键菜单) < div class ="demo3" id ="showOne" > JQuery之ContextMenu(右键菜单)  显示第一项 JQuery之ContextMenu(右键菜单) </ div > JQuery之ContextMenu(右键菜单) < hr /> JQuery之ContextMenu(右键菜单) < div class ="demo3" id ="showAll" > JQuery之ContextMenu(右键菜单)  显示全部 JQuery之ContextMenu(右键菜单) </ div > JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单) < hr /> JQuery之ContextMenu(右键菜单)    <!-- 右键菜单的源 --> JQuery之ContextMenu(右键菜单)     < div class ="contextMenu" id ="myMenu1" > JQuery之ContextMenu(右键菜单)      < ul > JQuery之ContextMenu(右键菜单)        < li id ="open" >< img src ="folder.png" /> 打开 </ li > JQuery之ContextMenu(右键菜单)        < li id ="email" >< img src ="email.png" /> 邮件 </ li > JQuery之ContextMenu(右键菜单)        < li id ="save" >< img src ="disk.png" /> 保存 </ li > JQuery之ContextMenu(右键菜单)        < li id ="delete" >< img src ="cross.png" /> 关闭 </ li > JQuery之ContextMenu(右键菜单)      </ ul > JQuery之ContextMenu(右键菜单)    </ div > JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单)    < div class ="contextMenu" id ="myMenu2" > JQuery之ContextMenu(右键菜单)        < ul > JQuery之ContextMenu(右键菜单)          < li id ="item_1" > 选项一 </ li > JQuery之ContextMenu(右键菜单)          < li id ="item_2" > 选项二 </ li > JQuery之ContextMenu(右键菜单)          < li id ="item_3" > 选项三 </ li > JQuery之ContextMenu(右键菜单)          < li id ="item_4" > 选项四 </ li > JQuery之ContextMenu(右键菜单)        </ ul > JQuery之ContextMenu(右键菜单)   </ div > JQuery之ContextMenu(右键菜单)    JQuery之ContextMenu(右键菜单)     < div class ="contextMenu" id ="myMenu3" > JQuery之ContextMenu(右键菜单)         < ul > JQuery之ContextMenu(右键菜单)          < li id ="item_1" > csdn </ li > JQuery之ContextMenu(右键菜单)          < li id ="item_2" > javaeye </ li > JQuery之ContextMenu(右键菜单)          < li id ="item_3" > itpub </ li > JQuery之ContextMenu(右键菜单)        </ ul > JQuery之ContextMenu(右键菜单)    </ div > JQuery之ContextMenu(右键菜单) </ BODY > JQuery之ContextMenu(右键菜单) < script > JQuery之ContextMenu(右键菜单)    //所有class为demo1的span标签都会绑定此右键菜单 JQuery之ContextMenu(右键菜单)     $('span.demo1').contextMenu('myMenu1', JQuery之ContextMenu(右键菜单)     { JQuery之ContextMenu(右键菜单)          bindings: JQuery之ContextMenu(右键菜单)          { JQuery之ContextMenu(右键菜单)            'open': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was Open'); JQuery之ContextMenu(右键菜单)            }, JQuery之ContextMenu(右键菜单)            'email': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was Email'); JQuery之ContextMenu(右键菜单)            }, JQuery之ContextMenu(右键菜单)            'save': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was Save'); JQuery之ContextMenu(右键菜单)            }, JQuery之ContextMenu(右键菜单)            'delete': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was Delete'); JQuery之ContextMenu(右键菜单)            } JQuery之ContextMenu(右键菜单)          } JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单)    }); JQuery之ContextMenu(右键菜单)    //所有html元素id为demo2的绑定此右键菜单 JQuery之ContextMenu(右键菜单)    $('#demo2').contextMenu('myMenu2', { JQuery之ContextMenu(右键菜单)      //菜单样式 JQuery之ContextMenu(右键菜单)      menuStyle: { JQuery之ContextMenu(右键菜单)        border: '2px solid #000' JQuery之ContextMenu(右键菜单)      }, JQuery之ContextMenu(右键菜单)      //菜单项样式 JQuery之ContextMenu(右键菜单)      itemStyle: { JQuery之ContextMenu(右键菜单)        fontFamily : 'verdana', JQuery之ContextMenu(右键菜单)        backgroundColor : 'green', JQuery之ContextMenu(右键菜单)        color: 'white', JQuery之ContextMenu(右键菜单)        border: 'none', JQuery之ContextMenu(右键菜单)        padding: '1px' JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单)      }, JQuery之ContextMenu(右键菜单)      //菜单项鼠标放在上面样式 JQuery之ContextMenu(右键菜单)      itemHoverStyle: { JQuery之ContextMenu(右键菜单)        color: 'blue', JQuery之ContextMenu(右键菜单)        backgroundColor: 'red', JQuery之ContextMenu(右键菜单)        border: 'none' JQuery之ContextMenu(右键菜单)      }, JQuery之ContextMenu(右键菜单)      //事件    JQuery之ContextMenu(右键菜单)      bindings: JQuery之ContextMenu(右键菜单)          { JQuery之ContextMenu(右键菜单)            'item_1': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was item_1'); JQuery之ContextMenu(右键菜单)            }, JQuery之ContextMenu(右键菜单)            'item_2': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was item_2'); JQuery之ContextMenu(右键菜单)            }, JQuery之ContextMenu(右键菜单)            'item_3': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was item_3'); JQuery之ContextMenu(右键菜单)            }, JQuery之ContextMenu(右键菜单)            'item_4': function(t) { JQuery之ContextMenu(右键菜单)              alert('Trigger was '+t.id+'\nAction was item_4'); JQuery之ContextMenu(右键菜单)            } JQuery之ContextMenu(右键菜单)          } JQuery之ContextMenu(右键菜单)    }); JQuery之ContextMenu(右键菜单)    //所有div标签class为demo3的绑定此右键菜单 JQuery之ContextMenu(右键菜单)    $('div.demo3').contextMenu('myMenu3', { JQuery之ContextMenu(右键菜单)    //重写onContextMenu和onShowMenu事件 JQuery之ContextMenu(右键菜单)      onContextMenu: function(e) { JQuery之ContextMenu(右键菜单)        if ($(e.target).attr('id') == 'dontShow') returnfalse; JQuery之ContextMenu(右键菜单)        elsereturntrue; JQuery之ContextMenu(右键菜单)      }, JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单)      onShowMenu: function(e, menu) { JQuery之ContextMenu(右键菜单)        if ($(e.target).attr('id') == 'showOne') { JQuery之ContextMenu(右键菜单)          $('#item_2, #item_3', menu).remove(); JQuery之ContextMenu(右键菜单)        } JQuery之ContextMenu(右键菜单)        return menu; JQuery之ContextMenu(右键菜单)      } JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单)    }); JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单) JQuery之ContextMenu(右键菜单) </ script > JQuery之ContextMenu(右键菜单) </ HTML > JQuery之ContextMenu(右键菜单)

效果图:

你可能感兴趣的:(contextMenu)