HTML - <menuitem> 標籤



HTML <menuitem> 標籤用於定義選單的選單項。

HTML menuitem 元素建立一個使用者可以透過彈出選單呼叫的命令,這包括上下文選單以及可能附加到選單按鈕的選單。

此標籤不再推薦,因為它已棄用且在 HTML5 中不受支援。

語法

<menuitem label = "" onclick = ""></menuitem>

屬性

HTML menuitem 標籤支援 HTML 的全域性事件屬性。還接受一些特定的屬性,如下所示。

屬性 描述
checked HTML-5 checked 定義選單項應被選中
command HTML-5
default HTML-5 default 選單項被標記為預設命令
disabled HTML-5 disabled 停用選單項,無法單擊
icon HTML-5 url 為選單項定義圖示
label HTML-5 text 為選單項定義一個名稱,顯示給使用者
radiogroup HTML-5 groupname 定義一組命令,其中只能選擇一個
type HTML-5

checkbox

command

radio

定義選單項的命令型別,預設為 command

HTML menuitem 標籤示例

下面的示例將說明 menuitem 標籤的使用。在哪裡、何時以及如何使用 menuitem 標籤建立選單項。示例僅在 Mozilla Firefox 上有效。

建立 menuitem 元素

讓我們看一下下面的示例,我們將使用 menuitem 標籤。

<!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>
        </menu>
 
    </div>
</body>
 
</html>

具有不同選單項的上下文選單

在下面的示例中,我們將建立具有不同選單項的上下文選單,例如 - Instagram、Twitter 和 Facebook。

<!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="mymenu">
            <menuitem label="Refresh" 
                      onclick="window.location.reload();" 
                      icon="ico_reload.png">
            </menuitem>
            <menu label="Share on...">
                <menuitem label="Instagram" icon="ico_instagram.png" 
                          onclick=
"window.open('//instagram.com/sharer/sharer?text=' + window.location.href);"> 
                </menuitem>
                <menuitem label="Twitter" icon="ico_twitter.png" 
                          onclick=
"window.open('//twitter.com/intent/tweet?text=' + window.location.href);"> 
                </menuitem>
                <menuitem label="Facebook" icon="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>
</body>

</html>

支援的瀏覽器

標籤 Chrome Edge Firefox Safari Opera
menuitem 是 8.0(上下文選單)
html_deprecated_tags.htm
廣告

© . All rights reserved.