动态添加弹出窗口后 XUL MenuItem 消失
我正在尝试将子菜单添加到动态构建的弹出菜单中,该菜单在您右键单击浏览器窗口中的任意位置时出现。第一级构建得很好,但是当我尝试向这些条目添加弹出窗口时,菜单项消失了。
这是我正在构建的对象:
var snpshot = {
'Head':'',
'Subhead':'',
'Date':'',
'Url':'',
};
这是存储在 onLoad 事件中的代码,因此在浏览器启动时构建菜单:
似乎不起作用的部分是 rclickItem.appendChild(mPopup) - 它正在做“某事”,但弹出的菜单项被添加为空白并缩小,尽管将光标滚动到它上面似乎表明它们仍然存在。
onLoad: function() {
var mainPop = document.createElementNS(XUL_NS, "menupopup");
mainPop.setAttribute('id', 'rclickMenu_MenuPopupContainer');
//attach it to main rclick object
var mainRclick = document.getElementById("rclickMenu_Main");
mainRclick.appendChild(mainPop);
mainOverlay.createMainRclick(); //THIS WORKS
//add popups -- AS SOON AS THE POPUPS ARE ADDED THE ENTRIES DISAPPEAR!
mainOverlay.createPopUpMenus();
},
createMenuItem: function(lblToUse){
//create the XUL menuitem
var itemToAdd = document.createElementNS(XUL_NS, "menuitem");
itemToAdd.setAttribute('label',lblToUse);
itemToAdd.setAttribute('id','rclickMenu_'+lblToUse);
return itemToAdd;
},
createMenuPopup: function(idToUse){
var mPopup = document.createElementNS(XUL_NS, "menupopup");
mPopup.setAttribute('id','rclickMenuPopup_' + idToUse );
return mPopup;
},
createMainRclick: function(){
for (var property in snpshot){
var mItem = mainOverlay.createMenuItem( property );
var mainPop = document.getElementById("rclickMenu_MenuPopupContainer");
mainPop.appendChild(mItem);
}
},
createPopUpMenus: function(){
for (var property in snpshot){
var mPopup = mainOverlay.createMenuPopup( property );
var rclickItem = document.getElementById("rclickMenu_"+property);
rclickItem.appendChild(mPopup);
}
},
和 XUL(这是右键单击时出现的主要弹出窗口,添加了我的菜单项(我在 js 中动态添加到该菜单项)
<menupopup id="contentAreaContextMenu">
<menu
id="rclickMenu_Main"
label="Main Section">
</menu>
</menupopup>
I am trying to add submenus to a dynamically built popup menu that appears when your right click anywhere in the browser window. The first level is built fine, but when I try to add a popup to those entries, the menu items disappear.
this is the object i'm building from:
var snpshot = {
'Head':'',
'Subhead':'',
'Date':'',
'Url':'',
};
This is the code stored in my onLoad event so the menu is built when the browser starts:
the part that doesn't seem to work is rclickItem.appendChild(mPopup) -- it is doing 'something' but the menu entries the popup is added to go blank and shrink, though rolling the cursor over it seems to suggest that they are still there.
onLoad: function() {
var mainPop = document.createElementNS(XUL_NS, "menupopup");
mainPop.setAttribute('id', 'rclickMenu_MenuPopupContainer');
//attach it to main rclick object
var mainRclick = document.getElementById("rclickMenu_Main");
mainRclick.appendChild(mainPop);
mainOverlay.createMainRclick(); //THIS WORKS
//add popups -- AS SOON AS THE POPUPS ARE ADDED THE ENTRIES DISAPPEAR!
mainOverlay.createPopUpMenus();
},
createMenuItem: function(lblToUse){
//create the XUL menuitem
var itemToAdd = document.createElementNS(XUL_NS, "menuitem");
itemToAdd.setAttribute('label',lblToUse);
itemToAdd.setAttribute('id','rclickMenu_'+lblToUse);
return itemToAdd;
},
createMenuPopup: function(idToUse){
var mPopup = document.createElementNS(XUL_NS, "menupopup");
mPopup.setAttribute('id','rclickMenuPopup_' + idToUse );
return mPopup;
},
createMainRclick: function(){
for (var property in snpshot){
var mItem = mainOverlay.createMenuItem( property );
var mainPop = document.getElementById("rclickMenu_MenuPopupContainer");
mainPop.appendChild(mItem);
}
},
createPopUpMenus: function(){
for (var property in snpshot){
var mPopup = mainOverlay.createMenuPopup( property );
var rclickItem = document.getElementById("rclickMenu_"+property);
rclickItem.appendChild(mPopup);
}
},
And the XUL (this is the main popup that comes up when you right click, with my menu item added (which I dynamically add to in the js)
<menupopup id="contentAreaContextMenu">
<menu
id="rclickMenu_Main"
label="Main Section">
</menu>
</menupopup>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自
文档:。 menuitem> 标签不在该列表中。事实上,您的
标记的父级应该是作为参考,将
添加到标记时会发生什么:此标记会替换
。然而
不是视觉元素,因此您得到的是一个没有任何可见内容的菜单项。From
<menupopup>
documentation:Note that
<menuitem>
tag is not on that list. In fact, the parents of your<menupopup>
tags should be<menu>
tags - then you will get a submenu (see documentation). A<menuitem>
tag is always a single menu item.For reference, what happens when you add
<menupopup>
to a<menuitem>
tag: this tag replaces the auto-generated contents of<menuitem>
.<menupopup>
isn't a visual element however so what you get is a menu item without any visible content whatsoever.