html5 动态 menuitem,<menuitem>

This is an experimental technology

Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The 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.

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 and .)

Permitted content

None, it is an empty element.

Tag omission

Must have a start tag and must not have an end tag.

Permitted parents

The

Permitted ARIA roles

None

Attributes

This element includes the global attributes; 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 attribute is checkbox or radio.

command

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, disabled, 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).

disabled

Boolean attribute which indicates that the command is not available in the current state. Note that disabled is distinct from hidden; the disabled 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 command 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 attribute is radio.

type

This attribute indicates the kind of command, and can be one of three values.

command: 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.

Example

HTML content

Right-click to see the adjusted context menu

checked="true">Checkbox

οnclick="doSomething()">Checkbox

checked="true">Radio button 1

οnclick="option()">Radio button 2

CSS content

div {

width: 300px;

height: 80px;

background-color: lightgreen;

}

Result

Specifications

Browser compatibility

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Edge

Opera

Safari

Basic support

No support[1]

8 (8)[2]

No support

No support

(Yes)[3]

?

Feature

Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

8.0 (8)

No support

No support

No support

[1] Not anymore due to compatibility issues. Only with commandline flag --enable-blink-features=ContextMenu. See Chromium bug.

[2] Only works for defined within a

[3] This is implemented behind the preference Enable experimental Web Platform features and only supports type="command".

See also

这篇文章有帮助吗?

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值