[英]appendChild in a XUL Firefox addon breaks
我正在开发一个Firefox插件,我目前需要动态地将菜单项添加到menupopup元素中。 我基本上尝试过Mozilla开发人员中心的所有方法,但没有一种方法可行。
function populateDropdown() {
var counter = 0;
for (var key in services) {
var newMenuItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
newMenuItem.setAttribute("label", services[key]['title'])
document.getElementById("mainDropdown").appendChild(newMenuItem);
}
}
这段代码在appendChild命令中断。 有什么想法吗?
你100%肯定document.getElementById(“mainDropdown”)返回非null结果吗?
尝试将其分解成碎片,并添加一些调试代码以跟进:
var dropDown = document.getElementById("mainDropdown");
if(dropDown) {
alert("dropDown found!");
dropDown.appendChild(newMenuItem);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.