1

我正在使用 contextmenu.js(jQuery 上下文菜单插件)在右键单击 div 时打开上下文菜单。但不知何故,只有默认菜单正在打开。我无法找到确切的问题。

在调试时,它显示右键单击它会将上下文菜单附加到 div。但是当我右键单击 div 时,会打开默认菜单。

我知道我提供的信息非常有限,但任何建议和帮助都将是可观的。

谢谢。

4

2 回答 2

0

I think you should do something like this, if that is your element that should get the menu

<div id="item-1">This should have a menu</div>

Then your javascript should look like this:

$(document).ready( function() {
  $('#item-1').contextMenu({
    menue: 'menueName'
  },
  function(action, el, pos) {
    // do sth when the menu was clicked
    alert('Action ' + action + ' was clicked on ' + $(el).attr('id'));
  });
});

The menue itselfe should defined in a list like:

<ul id="#menueName" class="contextMenu">
  <li class="action1">
    <a href="#action1>Action 1</a>
  </li>
  <li class="action1">
    <a href="#action2>Action 2</a>
  </li>
</ul>

Also make sure you have jQuery 1.3 or above included in your page.

于 2012-04-20T11:01:54.180 回答
0

我有同样的问题。if(jQuery)( function() {在 jquery.contextMenu.js 的开头替换为(function($, undefined){修复了问题。我希望这会有所帮助。

于 2012-05-24T13:05:07.350 回答