I have a ff extension 开发者_运维知识库which creates a popup and shows dynamic data in it. basically when the popup opens a js function is run which then constructs the popup list by appending the items like this
var myMenuPopup = document.getElementById("file-popup4");
newItem = document.createElement("menuitem");
newItem.setAttribute("label", namelist[m]);
newItem.setAttribute("id", "item" + m);
Now I need to have the click functionality too on these newly added menuitems. putting the atttribute and forming the function is easy. I can have a function to be run when they are clicked. But i need to pass namelist[i] to the function and it will act according to the namelist parameter.If i do:
newItem.setAttribute("oncommand" , finalclick(namelist[m]));
it runs the function everytime the popup opens runs the function without even clicking on it
on the other hand if i use quotes i.i if i do
newItem.setAttribute("oncommand" , "finalclick(namelist[m])");
it doesnot open even on clicking giving error : namelist is not defined.
newItem.setAttribute("oncommand" , "finalclick(\"" + namelist[m] + "\")");
精彩评论