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
type
属性为
checkbox
or
radio
.
命令
checked
,
被禁用
,
icon
,
label
,
radiogroup
or
type
.
default
button
or
input
).
被禁用
被禁用
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
命令
attribute is not present.
radiogroup
type
属性为
radio
.
type
命令
: 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.
<!-- 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>
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 实时标准 ,初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
menuitem
弃用
|
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 |
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 |
完整支持
不支持
弃用。不要用于新网站。
见实现注意事项。