Joe*_*gen 5 javascript firefox xul firefox-addon
我正在开发一个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);
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码在appendChild命令中断.有什么想法吗?
你100%肯定document.getElementById("mainDropdown")返回非null结果吗?
尝试将其分解成碎片,并添加一些调试代码以跟进:
var dropDown = document.getElementById("mainDropdown");
if(dropDown) {
alert("dropDown found!");
dropDown.appendChild(newMenuItem);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1121 次 |
| 最近记录: |