Javascript 上下文菜单?
我正在创建一个网络应用程序,当用户右键单击并偶然发现这个时,需要上下文菜单我非常喜欢。我遇到一个问题,当我为两个 div 元素分配两个不同的菜单时,两者都会出现相同的菜单。例如,下面的代码创建两个 div 元素,将它们放在页面上,然后为每个元素分配一个单独的上下文菜单。
this.leftDiv = document.createElement("div");
this.leftDiv.id = "Left_DIV";
document.body.appendChild(this.leftDiv);
$("#" + this.leftDiv.id).contextmenu(left_Options);
.........
this.rightDiv = document.createElement("div");
this.rightDiv.id = "Right_DIV";
document.body.appendChild(this.rightDiv);
$("#" + this.rightDiv.id).contextmenu(right_Options);
现在,当应用程序在浏览器中加载时,两个 div 都有 left_Options 菜单系统。
有人能推荐一个好的、易于使用的 javascript 上下文菜单吗?
干杯。
Im creating a web app that will need context menus when the user right clicks and have stumbled upon this one which i like very much. Im having a problem in that when i assign two div elements two different menus, the same menu appears for both. For example the code below creates two div elements, puts them onto the page and then assigns a seperate context menu for each of them.
this.leftDiv = document.createElement("div");
this.leftDiv.id = "Left_DIV";
document.body.appendChild(this.leftDiv);
$("#" + this.leftDiv.id).contextmenu(left_Options);
.........
this.rightDiv = document.createElement("div");
this.rightDiv.id = "Right_DIV";
document.body.appendChild(this.rightDiv);
$("#" + this.rightDiv.id).contextmenu(right_Options);
Now when the app is loaded in the browser, both of the divs have the left_Options menu system.
Would anyone be able to recommend a good javascript context menu that is easy to use?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您链接到的网站,看起来好像一组选项应用于所有“div”元素。它假定您希望所有上下文菜单都有类似的选项。
为了自定义每个单独的菜单,您添加一个“onShow”选项,该选项可以运行启用/禁用某些项目的功能。我不确定这对于完全不同的菜单有多灵活。
快速搜索发现了这个: http://www.trendskitchens.co.nz/jquery/contextmenu / 它声称支持单个页面上的多个菜单,所以也许这就是您正在寻找的。我没用过。
Based on the site that you linked to, it looks as if one set of options is applied to all of the 'div' elements. It presumes that you want to have similar options for all of your context menus.
In order to customize each individual menu, you add an 'onShow' option that can run a function enable/disable some items. I'm not sure how flexible this is for completely different menus.
A quick search turned up this: http://www.trendskitchens.co.nz/jquery/contextmenu/ It claims to support multiple menus on a single page, so perhaps that's what you're looking for. I have not used it.