如何将上下文菜单附加到按钮
How to attach a context menu to a button
我正在尝试将上下文菜单附加到工具栏上的按钮。
这是我的代码:
contex_order = new dhtmlXMenuObject();
contex_order.renderAsContextMenu();
contex_order.loadStruct(cont_m);
...
toolbarOrder = new dhtmlXToolbarObject("tab_ord");
toolbarOrder.setIconsPath("dhtmlx/codebase/imgs/");
toolbarOrder.attachEvent("onClick", function(id){
if (id=="save")
contex_order.showContextMenu(100,50)
});
但是单击该按钮不会显示上下文菜单。浏览器控制台没有报错,什么都没有。
有人遇到过这样的问题吗?如何显示菜单?
请尝试使用超时调用 showContextMenu() 方法:
setTimeout(function() {
contex_order.showContextMenu(100,50)
}, 50)
因为菜单是在点击按钮的同时出现的,所以点击这个按钮会同时关闭菜单。
我正在尝试将上下文菜单附加到工具栏上的按钮。
这是我的代码:
contex_order = new dhtmlXMenuObject();
contex_order.renderAsContextMenu();
contex_order.loadStruct(cont_m);
...
toolbarOrder = new dhtmlXToolbarObject("tab_ord");
toolbarOrder.setIconsPath("dhtmlx/codebase/imgs/");
toolbarOrder.attachEvent("onClick", function(id){
if (id=="save")
contex_order.showContextMenu(100,50)
});
但是单击该按钮不会显示上下文菜单。浏览器控制台没有报错,什么都没有。
有人遇到过这样的问题吗?如何显示菜单?
请尝试使用超时调用 showContextMenu() 方法:
setTimeout(function() {
contex_order.showContextMenu(100,50)
}, 50)
因为菜单是在点击按钮的同时出现的,所以点击这个按钮会同时关闭菜单。