当 <menu> 元素在 HTML 中显示为上下文菜单时,是否执行脚本?

htmlweb developmentfront end technology更新于 2026/1/16 11:24:17

当 <menu> 元素在 HTML 中显示为上下文菜单时,会触发 onshow 事件。

示例

您可以尝试运行以下代码,在 <menu> 元素显示为上下文菜单时执行脚本 −

<!Doctype html>
<html>
   <head>
      <title>HTML menu</title>
   </head>
   <body>
      <div style = "border:1px solid #000; padding:20px;" contextmenu = "clickmenu">
         <p>Right click inside here....</p>

         <menu type = "context" id = "clickmenu" onshow="display()">
            <menuitem label = "Tutorialspoint" onclick = ""></menuitem>
            <menuitem label = "Tutorials Library" onclick = ""></menuitem>
            <menuitem label = "Coding Ground" onclick = ""></menuitem>
            <menuitem label = "Q/A" onclick = ""></menuitem>
         </menu>

      </div>
      <script>
         function display() {
            alert("The context menu will be visible now.");
         }
      </script>
   </body>
</html>

相关文章


有用资源