【问题标题】:appendChild in a XUL Firefox addon breaksXUL Firefox 插件中的 appendChild 中断
【发布时间】:2009-06-18 13:48:59
【问题描述】:

我正在开发一个 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 命令处中断。任何想法为什么?

【问题讨论】:

  • 我认为您不需要使用 createElementNS。它已经是一个 XUL 文档,所以 createElement 默认应该只创建一个 XUL 元素。
  • @Gryllida 是的,我认为是这样,或者更一般地说,将标签插入到一个命名空间中,插入到具有不同命名空间的文档中。

标签: javascript firefox firefox-addon xul


【解决方案1】:

您是否 100% 肯定 document.getElementById("mainDropdown") 返回非空结果?

尝试将其分解成小块,并添加一些调试代码以跟进:

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

【讨论】:

    猜你喜欢
    • 2011-11-15
    • 2014-04-28
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多