W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <style> div { background: yellow; border: 1px solid #cccccc; padding: 10px; } </style> </head> <body> <p>本例演示如何将 "onshow" 事件分配给 menu 元素。</p> <div contextmenu="mymenu"> <p>在此框中右键单击以查看上下文菜单! <menu type="context" id="mymenu" onshow="myFunction()"> <menuitem label="Refresh" onclick="window.location.reload();" icon="/i/ico_reload.png"></menuitem> <menu label="Share on..."> <menuitem label="Twitter" icon="/i/ico_twitter.png" onclick="window.open('//twitter.com/intent/tweet?text=' + window.location.href);"></menuitem> <menuitem label="Facebook" icon="/i/ico_facebook.png" onclick="window.open('//facebook.com/sharer/sharer.php?u=' + window.location.href);"></menuitem> </menu> <menuitem label="Email This Page" onclick="window.location='mailto:?body='+window.location.href;"></menuitem> </menu> </div> <p><b>注释:</b>onshow 事件目前仅在 Firefox 中受支持。</p> <script> function myFunction() { alert("The context menu is about to be shown"); } </script> </body> </html>