2009-06-18 41 views
5

我正在使用Firefox插件,而我目前需要动态地将menuitems添加到menupopup元素。我基本上已经尝试了Mozilla开发人员中心的所有方法,但都没有工作。appendChild在XUL Firefox插件中打破

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命令处中断。任何想法为什么?

+1

得到一个错误信息? – geowa4 2009-06-18 14:32:35

回答

5

你是否100%肯定document.getElementById(“mainDropdown”)返回一个非空结果?

试着将它分解成块,并添加一些调试代码后续沿:

var dropDown = document.getElementById("mainDropdown"); 
if(dropDown) { 
    alert("dropDown found!"); 
    dropDown.appendChild(newMenuItem); 
}