HTML5中的上下文菜单属性示例
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"
<title>Context menu Attribute in HTML5</title>
</head>
<body>
This paragraph has a context menu called "menu". The context menu should appear when a user right-clicks on this paragraph.
<menu id="menu">
<command label="New">
<command label="Open">
<command label="Save">
<command label="Copy">
<command label="Paste">
<command label="Write Tutorial" onclick="doSomething()">
<command label="Edit Tutorial" onclick="doSomethingElse()">
</menu>
</menu>
<p></p>
</body>
</html>
HTML5 ContextMenu属性语法
<element contentmenu="menu-id">
ContextMenu属性
基本上,它允许我们将不同的选项添加到浏览器的右键单击菜单中,只需几行HTML,甚至会禁用JavaScript。
虽然很遗憾,它目前不支持任何主要浏览器。
ContextMenu属性指定元素的上下文菜单。
当用户右键单击元素时,将显示上下文菜单。
ContentMenu属性在HTML5中是新的。
ContextMenu属性的值是要打开的<MENU>元素的ID。
菜单项可以具有"label","icon"和"onClick"属性。
使用'ContextMenu'比你想象的更简单。
我们所需要的只是添加"ContextMenu"属性,如下所示:
<section contextmenu="my-right-click-menu"> <!-- 添加需要的内容 --> </section>
正如我们可以看到的那样,我们可以像你添加任何"id"或者'class'一样添加它。
接下来我们创建菜单:
<menu type="context" id="my-right-click-menu"> <!-- 这里添加右键点击时显示的菜单项 --> </menu>
日期:2020-04-11 23:04:03 来源:oir作者:oir
