简体   繁体   中英

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 link 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM