<menuitem>

Deprecated: 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 compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

<menuitem> HTML 元素表示用户能够通过弹出菜单调用的命令。这包括上下文菜单以及可能附加到菜单按钮的菜单。

¥The <menuitem> HTML 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.

命令可以明确定义,使用文本标签和可选图标来描述其外观,也可以作为间接命令,其行为由单独的元素定义。命令还可以选择包含复选框或分组以共享单选按钮。(针对元素 <input type="checkbox"><input type="radio"> 定义时,间接命令的菜单项会获得复选框或单选按钮。)

¥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">.)

属性

¥Attributes

该元素包括 全局属性;特别是 title 可用于描述命令,或提供使用提示。

¥This element includes the global attributes; in particular title can be used to describe the command, or provide usage hints.

checked Deprecated Non-standard

布尔属性,指示是否选择该命令。仅当 type 属性为 checkboxradio 时才可使用。

command Deprecated Non-standard

指定单独元素的 ID,指示要间接调用的命令。不得在还包含属性 checkeddisablediconlabelradiogrouptype 的菜单项中使用。

default Deprecated Non-standard

该布尔属性指示使用与菜单主题元素相同的命令(例如 buttoninput)。

disabled Deprecated Non-standard

布尔属性,指示该命令在当前状态下不可用。请注意,disabledhidden 不同;disabled 属性适用于环境变化可能导致命令相关的任何上下文。

icon Deprecated Non-standard

图片 URL,用于提供代表命令的图片。

label

显示给用户的命令名称。当 command 属性不存在时为必需。

radiogroup Deprecated Non-standard

此属性指定一组命令的名称,这些命令在选择时将作为单选按钮进行切换。只能在 type 属性为 radio 的情况下使用。

type Deprecated Non-standard

该属性指示命令的类型,并且可以是三个值之一。

  • command:带有关联操作的常规命令。这是缺失值的默认值。
  • checkbox:表示可以在两种不同状态之间切换的命令。
  • radio:表示可以作为单选按钮切换的一组命令中的一个选择。

示例

¥Examples

HTML

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="favicon-192x192.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

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

结果

¥Result

技术总结

¥Technical summary

内容类别 没有任何。
允许的内容 没有任何;这是 void element
标签遗漏 必须有开始标记,并且不能有结束标记。
允许的父级 <menu> 元素,该元素处于弹出菜单状态。(如果指定,则 <menu> 元素的 type 属性必须是 popup;如果缺少,<menu> 的父元素本身必须是处于弹出菜单状态的 <menu>。)
允许的 ARIA 角色 没有任何
DOM 接口 HTMLMenuItemElement

规范

¥Specifications

不属于任何当前规范的一部分。

¥Not part of any current specifications.

浏览器兼容性

¥Browser compatibility

任何浏览器均不再支持。Firefox 是唯一支持此元素的浏览器,在 85 中删除了支持。

¥No longer supported in any browser. Firefox, the only browser that supported this element, removed support in 85.

也可以看看