Deprecated since HTML5.2
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the 兼容性表格 at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

HTML <menuitem> element represents a command that a user is able to invoke through a popup menu. This includes context menus, as well as menus that might be attached to a menu button.

A command can either be defined explicitly, with a textual label and optional icon to describe its appearance, or alternatively as an indirect command whose behavior is defined by a separate element. Commands can also optionally include a checkbox or be grouped to share radio buttons. (Menu items for indirect commands gain checkboxes or radio buttons when defined against elements <input type="checkbox"> and <input type="radio"> )。

内容类别 None.
准许内容 None, it is an empty element .
Tag omission Must have a start tag and must not have an end tag.
Permitted parents <menu> element, where that element is in the popup menu state. (If specified, the type 属性在 <menu> element must be popup ; if missing, the parent element of the <menu> must itself be a <menu> popup menu state.)
Permitted ARIA roles None
DOM 接口 HTMLMenuItemElement

属性

此元素包括 全局属性 ; in particular title can be used to describe the command, or provide usage hints.

checked
Boolean attribute which indicates whether the command is selected. May only be used when the type 属性为 checkbox or radio .
命令
Specifies the ID of a separate element, indicating a command to be invoked indirectly. May not be used within a menu item that also includes the attributes checked , 被禁用 , icon , label , radiogroup or type .
default
This Boolean attribute indicates use of the same command as the menu's subject element (such as a button or input ).
被禁用
Boolean attribute which indicates that the command is not available in the current state. Note that 被禁用 is distinct from hidden 被禁用 attribute is appropriate in any context where a change in circumstances might render the command relevant.
icon

Image URL, used to provide a picture to represent the command.

label
The name of the command as shown to the user. Required when a 命令 attribute is not present.
radiogroup
This attribute specifies the name of a group of commands to be toggled as radio buttons when selected. May only be used where the type 属性为 radio .
type
This attribute indicates the kind of command, and can be one of three values.
  • 命令 : A regular command with an associated action. This is the missing value default.
  • checkbox : Represents a command that can be toggled between two different states.
  • radio : Represent one selection from a group of commands that can be toggled as radio buttons.

范例

HTML 内容

<!-- A <div> element with a context menu -->
<div contextmenu="popup-menu">
  Right-click to see the adjusted context menu
</div>
<menu type="context" id="popup-menu">
  <menuitem type="checkbox" checked>Checkbox</menuitem>
  <hr>
  <menuitem type="command" label="This command does nothing" icon="https://developer.cdn.mozilla.net/static/img/favicon144.png">
    Commands don't render their contents.
  </menuitem>
  <menuitem type="command" label="This command has javascript" onclick="alert('command clicked')">
    Commands don't render their contents.
  </menuitem>
  <hr>
  <menuitem type="radio" radiogroup="group1">Radio Button 1</menuitem>
  <menuitem type="radio" radiogroup="group1">Radio Button 2</menuitem>
</menu>
					

CSS content

div {
  width: 300px;
  height: 80px;
  background-color: lightgreen;
}
					

结果

规范

规范 状态 注释
HTML 5.2
The definition of '<menuitem>' in that specification.
推荐 Snapshot of the HTML 实时标准 , made obsolete.
HTML 5.1
The definition of '<menuitem>' in that specification.
推荐 Snapshot of the HTML 实时标准 ,初始定义。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
menuitem 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 注意事项
完整支持 8 注意事项
注意事项 Only works for <menuitem> elements defined within a <menu> element assigned to an element via the contextmenu 属性。
注意事项 <menuitem> element requires a closing tag.
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 注意事项
完整支持 8 注意事项
注意事项 Only works for <menuitem> elements defined within a <menu> element assigned to an element via the contextmenu 属性。
注意事项 <menuitem> element requires a closing tag.
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
checked 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
命令 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
default 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
被禁用 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
icon 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
radiogroup 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
type 弃用 Chrome 不支持 No Edge 不支持 No Firefox 完整支持 8 IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 完整支持 8 Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改: