<p>该实例演示了如何向 menu 元素中添加 "onshow" 事件。</p> <div contextmenu="mymenu"> <p>用鼠标右键单击黄色框区域查看上下文菜单!</p> <menu type="context" id="mymenu" onshow="myFunction()"> <menuitem label="Refresh" onclick="window.location.reload();" icon="ico_reload.png"> <menu label="Share on..."> <menuitem label="Twitter" icon="ico_twitter.png" onclick="window.open(\'//twitter.com/intent/tweet?text=\' + window.location.href);"> <menuitem label="Facebook" icon="ico_facebook.png" onclick="window.open(\'//facebook.com/sharer/sharer.php?u=\' + window.location.href);"> </menu> <menuitem label="Email This Page" onclick="window.location=\'mailto:?body=\'+window.location.href;"> </menu> </div> <p><strong>注意:</strong>目前只有 Firefox 浏览器支持 onshow 属性。</p> <script> function myFunction() { alert("上下文菜单即将显示"); } </script>