如何在 HTML5 中為元素建立上下文選單?
在 HTML5 中使用 contextmenu 屬性來為元素建立上下文選單。點選右鍵時會生成上下文選單。
示例
你可以嘗試執行以下程式碼來建立上下文選單 −
<!Doctype html> <html> <head> <title>HTML menuitem Tag</title> </head> <body> <div style = "border:1px solid #000; padding:20px;" contextmenu = "clickmenu"> <p>Right click inside here....</p> <menu type = "context" id = "clickmenu"> <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> </body> </html>
廣告