appendChild在XUL Firefox插件中断
-
06-07-2019 - |
题
我正在开发一个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")返回非空结果?
尝试将其分解成碎片,然后添加一些调试代码以便跟进:
var dropDown = document.getElementById("mainDropdown");
if(dropDown) {
alert("dropDown found!");
dropDown.appendChild(newMenuItem);
}
不隶属于 StackOverflow