Javascript 在OnPopusShowing事件处理程序中确定的弹出窗口中动态显示数据
我正在开发一个Firefox扩展。在一个Javascript 在OnPopusShowing事件处理程序中确定的弹出窗口中动态显示数据,javascript,firefox,firefox-addon,xul,Javascript,Firefox,Firefox Addon,Xul,我正在开发一个Firefox扩展。在一个上,onpopushowing调用一个JavaScript函数。JavaScript函数提取名称列表。现在,这些名称必须显示在同一弹出窗口中 我怎么能得到这个?基本上,我需要将数据(就像我们在Java中使用bean一样)从JavaScript函数传递到浏览器。每次调用弹出窗口时,数据都会发生变化。您需要修改呈现菜单的DOM。 例如: <menulist> <menupopup id="myMenuPopup"> <
上,onpopushowing
调用一个JavaScript函数。JavaScript函数提取名称列表。现在,这些名称必须显示在同一弹出窗口中
我怎么能得到这个?基本上,我需要将数据(就像我们在Java中使用bean一样)从JavaScript函数传递到浏览器。每次调用弹出窗口时,数据都会发生变化。您需要修改呈现菜单的DOM。 例如:
<menulist>
<menupopup id="myMenuPopup">
<menuitem id="firstItem" label="Mozilla" value="http://mozilla.org"/>
<menuitem id="secondItem" label="Slashdot" value="http://slashdot.org"/>
<menuitem id="thirdItem" label="Sourceforge" value="http://sf.net"/>
</menupopup>
</menulist>
如果要删除项目,请执行以下操作:
var itemToRemove = myMenuPopup.getElementById("anotherItem");
myMenuPopup.appendChild(itemToRemove);
在这里,您可以找到更多信息:
编辑:
我假设您的函数返回一个名称数组:
var nameLists = yourFunction();
for (var i=0; i<nameList.length; i++){
var newItem = document.createElement("menuitem");
newItem.setAttribute("label", nameList[i]);
newItem.setAttribute("id", "item" + i);
myMenuPopup.appendChild(newItem);
}
var nameLists=yourFunction();
对于(var i=0;ihey kucebe,谢谢你的帮助。它现在可以工作了。到目前为止还不错。现在我需要在这些新添加的菜单项上也有单击功能。放置属性和形成函数很容易。我可以在单击它们时运行函数。但我需要传递名称列表[i]如果我这样做:newItem.setAttribute(“oncommand”,finalclick(namelist[m]);它会在每次弹出窗口打开时运行函数,而如果我执行newItem.setAttribute(“oncommand”,“finalclick(namelist[m]),它甚至不会点击它;另一方面,它会运行函数;它甚至在单击时也不会打开。错误:名称列表未定义。我认为如果您将事件侦听器设置为这样会更好:newItem.oncommand=function(){finalclick(namelist[m]);}在创建此菜单opup后,每个菜单项还需要有一个弹出窗口…因为每个新项都需要有另一个弹出窗口。我如何获得此结果?[我已经发布了一个同样的问题]
var nameLists = yourFunction();
for (var i=0; i<nameList.length; i++){
var newItem = document.createElement("menuitem");
newItem.setAttribute("label", nameList[i]);
newItem.setAttribute("id", "item" + i);
myMenuPopup.appendChild(newItem);
}