我在SVG图形中使用Rodney Rehm的
jQuery contextMenu.它适用于基本用法.
但是我需要获取触发上下文菜单的SVG-Element的ID(或任何其他属性)以在上下文菜单的项目列表中使用它来获取动态项目名称.
解决方法
这可能对您有所帮助:
http://medialize.github.com/jQuery-contextMenu/demo/dynamic-create.html
这是一些示例代码:
这是一些示例代码:
$(function(){ $.contextMenu({ selector: 'my-selector-here',build: function($trigger,e) { // this callback is executed every time the menu is to be shown // its results are destroyed every time the menu is hidden // e is the original contextmenu event,containing e.pageX and e.pageY (amongst other data) // $trigger is the element that was rightclicked on - get its id here var id = $trigger.getTheIDSomehow() // build the menu items if (id == 1) { menuItems = {...} else if (id == 2) menuItems = {...} return { callback: function(key,options) { // this is called when one of the contextmenu options is clicked },items: menuItems }; } }); });