最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - context menu on left mouse click? - Stack Overflow

programmeradmin0浏览0评论

the description of jsTree contextmenu says "The contextmenu plugin enables a contextual menu to be shown, when the user right-clicks a node (or when triggered programatically by the developer)."

could somebody tell me how

  • I can trigger the menu on left mouse click
  • leave the right mouse as it is

the description of jsTree contextmenu says "The contextmenu plugin enables a contextual menu to be shown, when the user right-clicks a node (or when triggered programatically by the developer)."

could somebody tell me how

  • I can trigger the menu on left mouse click
  • leave the right mouse as it is
Share Improve this question edited Apr 23, 2011 at 0:38 Blender 299k55 gold badges458 silver badges510 bronze badges asked Apr 23, 2011 at 0:32 RadekRadek 11.1k56 gold badges169 silver badges270 bronze badges 1
  • Please stop writing tags in question titles. – Lightness Races in Orbit Commented Apr 23, 2011 at 0:37
Add a ment  | 

3 Answers 3

Reset to default 5

Since JSTree 3

$('#jstree_list').jstree({
   ...
}).on('select_node.jstree', function (e, data) {
    setTimeout(function() {
        data.instance.show_contextmenu(data.node)
    }, 100);
});

The delay seems necessary, I don't know exactly why

You can trigger context menu on elem (eg. a <li>) by $(elem).trigger('contextmenu.jstree')

Had the same issue. Here's how you do it:

element.jstree({
  .
  .
  .
}).bind("select_node.jstree", function (event, data) {
  setTimeout(function() {data.rslt.obj.children('a').trigger('contextmenu')}, 100);
});

Note that the triggering is done in a setTimeout(). It did not work for me otherwise.

发布评论

评论列表(0)

  1. 暂无评论