开发者

ff extension. how to pass parameters to a function in the oncommand attribute in menu

开发者 https://www.devze.com 2022-12-28 09:17 出处:网络
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 ite

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] + "\")");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号