--- title: menu slug: Mozilla/Tech/XUL/menu tags: - XUL Elements - XUL Reference translation_of: Archive/Mozilla/XUL/menu ---
An element, much like a button, that is placed on a menubar. When the user clicks the menu element, the child menupopup of the menu will be displayed. This element is also used to create submenus.
More information is available in the XUL tutorial.
<menubar id="sample-menubar">
<menu id="file-menu" label="File">
<menupopup id="file-popup">
<menuitem label="New"/>
<menuitem label="Open"/>
<menuitem label="Save"/>
<menuseparator/>
<menuitem label="Exit"/>
</menupopup>
</menu>
<menu id="edit-menu" label="Edit">
<menupopup id="edit-popup">
<menuitem label="Undo"/>
<menuitem label="Redo"/>
</menupopup>
</menu>
</menubar>
accesskeylabel 属性文本中的一个字符。该字符将会被加下划线以重点强调,平台和主体的变换并不影响这一表现行为。 当用户点击 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>
alloweventscropcrop 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.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.
labelsizetopopupmenupopup 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.noneprefalwaysmenupopup.value
accessibleTypeitemCount parentContainer menu element
menu element, or null if there isn't a containing menu.appendItem( label, value )getIndexOfItem( item )getItemAtIndex( index )insertItemAt( index, label, value )removeItemAt( index )menubar, menuitem, menulist, menupopup, menuseparator