开发者

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

开发者 https://www.devze.com 2023-01-10 10:28 出处:网络
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 th

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

精彩评论

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

关注公众号