开发者

How to change the selected item in a Firefox Extension's Menulist?

I'm writing a firefox extension and I have a menulist of links that should be automatically (upon load) set to the last l开发者_开发百科ink it was set before I closed it. It just keep being set to the first menu item. I've tried using setAttribute('selectedIndex', 1), but that doesn't work. What am I doing wrong?

Some sample code:

<menulist>
 <menupopup>
   <menuitem label="default"/>
   <menuitem label="I want this one to be selected" />
   <menuitem label="Or this one." />
 </menupopup>
</menulist>


Set the selectedIndex property, not the attribute.

document.getElementById("mymenulistid").selectedIndex = 1;

After adding it to the document you usually need to edit properties for things like this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜