--- title: menulist slug: Mozilla/Tech/XUL/menulist tags: - XUL Elements - XUL Reference translation_of: Archive/Mozilla/XUL/menulist ---
An element that can be used for drop-down choice lists. The user may select one of the elements displayed in the menulist
. The currently selected choice is displayed on the menulist
element. To create the drop-down, put a menupopup
inside the menulist
containing the choices as menuitem
elements. The command event may be used to execute code when the menulist selection changes.
More information is available in the XUL tutorial.
<menulist> <menupopup> <menuitem label="option 1" value="1"/> <menuitem label="option 2" value="2"/> <menuitem label="option 3" value="3"/> <menuitem label="option 4" value="4"/> </menupopup> </menulist>
accesskey
label
属性文本中的一个字符。该字符将会被加下划线以重点强调,平台和主体的变换并不影响这一表现行为。 当用户点击 ALT (在其他平台上具有类似功能的键) 和这个字符对应的按键时, 控件(元素)将立刻被从窗口中的某处激活或/并且获得焦点 。虽说字符不分大小写,但是当label中存在大写字符和小写字符时,快捷键的字符将首先选择与之完全匹配的那一个,如果label中存在两个或更多的与accesskey字符相同的字符,其中的第一个字符将被加下划线。
<vbox> <label value="Enter Name" accesskey="e" control="myName"/> <textbox id="myName"/> <button label="Cancel" accesskey="n"/> <button label="Ok" accesskey="O"/> </vbox>
crop
crop
attribute. An ellipsis will be used in place of the cropped text. If the box direction is reversed, the cropping is reversed.start
: The text will be cropped on its left side.end
: The text will be cropped on its right side.left
: The text will be cropped on its left side.right
: The text will be cropped on its right side.center
: The text will be cropped in the middle, showing both the start and end of the text normally.none
: The text will be not be cropped using an ellipsis. However, the text will simply be cut off if it is too large. The side depends on the CSS text alignment.disableautoselect
true
or omitted, the selected item on the menu will update to match what the user entered in the textbox. If the text does not match any of the items in the list, the menu selection is cleared. If this attribute is false
, the selection is never updated to match the text box. This attribute applies only to editable menulist
s.disabled
如果这个元素的disabled属性被设置为true,表示元素被禁用,被禁用的属性在页面上通常会显示灰色文本,它无法响应用户的操作,它也无法得到光标。
然而,这个元素仍然能够响应鼠标事件,如果要启用这个元素,把disabled设置为false
// Disabling an element
document.getElementById('buttonRemove').setAttribute("disabled", "true");
// Enabling back an element by removing the "disabled" attribute
document.getElementById('buttonRemove').removeAttribute("disabled");
For keyset
elements, support for this attribute was added in Firefox 3.5.
focused
true
if the element is focused.label
oncommand
preference
preference
. This attribute only has any effect when used inside a prefwindow
. More information is available in the Preferences System article.readonly
true
, then the user cannot change the value of the element. However, the value may still be modified by a script.sizetopopup
menupopup
width are determined. If the sizetopopup
attribute is left out or set to none
, the menu will be its preferred width and the popup may extend outside of this width, unaffected by the maximum width of the menu itself. Otherwise, the menu will size itself to at least the size of the popup. If the menu has a maximum width, the popup will also be this width.none
pref
always
menupopup
.tabindex
tabindex
数字越大,顺序越靠后。value
accessibleType
description
menuitem
.disableautoselect
disableautoselect
attribute.editable
true
if the element is editable. Autocomplete fields are editable so this property always returns true
for those.
itemCount
selectedIndex
-1
to this property, all items will be deselected.selectedItem
null
. You can select an item by setting this value. A select event will be sent to the element when it is changed either via this property, the selectedIndex
property, or changed by the user.menuitem
element and adds it to the end of the menulist. You may optionally set a value and description. The function returns the new item.contains( item )
true
if the menulist
contains the specified menuitem
as one of its items.getIndexOfItem( item )
getItemAtIndex( index )
insertItemAt( index, label, value )
removeAllItems()
removeItemAt( index )
menulist
's textbox. This method applies to editable
menulists only.menu
, menubar
, menuitem
, menupopup
, menuseparator