當(dāng)一個(gè)具有contextmenu屬性的元素的contextmenu事件觸發(fā)或冒泡到該元素時(shí),show事件會(huì)被觸發(fā)。
當(dāng) <menu> 元素在上下文菜單顯示時(shí)執(zhí)行 JavaScript:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鳥教程(cainiaoplus.com)</title> </head> <body> <div contextmenu="test"></div> <menu type="context" id="test"> <menuitem label="alert" onclick="alert('the alert label has been clicked')" /> </menu> <script> document.getElementById("test").addEventListener("show", function(e){ alert("the context menu will be displayed"); }, false); </script> </body> </html>測(cè)試看看 ?/?
當(dāng)<menu>元素顯示為上下文菜單時(shí),將激活onshow屬性。
IEFirefoxOperaChromeSafari
目前只有瀏覽器firefox支持 onshow事件屬性。
onshow事件屬性是HTML5中的新增功能。
<element onshow="script">
值 | 描述 |
---|---|
script | 腳本在 onshow 中執(zhí)行 |
支持的 HTML 標(biāo)簽: | <menu> |
---|
HTML DOM 參考手冊(cè): onshow 事件