我听说上下文菜单已弃用:https://html.spec.whatwg.org/multipage/obsolete.html#attr-contextmenu
那么,有没有办法替代呢?
最佳答案
As the feature was not that popular, it is no longer supported. :
The support for HTML5 context menus, introduced with Firefox 8, will be removed soon. Other browser vendors were not interested in the feature, and therefore it has already been removed from the HTML spec, leaving Firefox as the only browser implementing the and elements as well as the contextmenu global attribute.
If desired, you can instead create your own context menu as seen in some rich web applications like Google Drive. The WAI-ARIA standard provides a way to create accessible menus which is highly recommended.
您可以使用 ARIA 创建自己的菜单。
而不是 <menu> & <menu-item>
您使用普通列表(<ul> & <li>
),装饰它们并使用 JS 来实现功能。
您会发现更多细节和预设 here和 here .
关于html - 如果不推荐使用 contextmenu 如何替换它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57424197/