Html5 development and learning (4): contextmenu -- Right-click menu

Source: Internet
Author: User

Previous: http://www.bkjia.com/kf/201203/124948.html

1, contextmenu
In Html5, each element adds a new attribute: contextmenu
Contextmenu is the context menu, that is, a menu appears when you right-click the element.
 
2, <menu>
To enable right-clicking, a menu appears. You must also understand another element added to html5: <menu>
As the name suggests, <menu> defines menus,
<Menu> element attributes:
Type: menu type.
There are three values
1) context: context;
2) toolbar: tool bar;
3) list: list
Label: The name displayed in the menu.

3, <menuitem>
<Menu> </menu> You can embed a menu item, that is, <menuitem> </menuitem>.
Menuitem attributes:
Label: name displayed for the menu item
Icon: icon displayed on the left of the menu item
Onclick: Click the event triggered by the menu item


4. The following Code demonstrates how to implement a right-click menu:
<Div style = 'display: inline' contextmenu = "mymenu"> right-click and try </div>

<Menu type = "context" id = "mymenu">
<Menuitem label = "menu 1" onclick = "alert ('this is menu 1');" icon = "http://d.lanrentuku.com/down/gif/gif-0145.gif"> </menuitem>
<Menuitem label = "menu 2" onclick = "alert ('this is menu 2');" icon = "http://d.lanrentuku.com/down/gif/gif-0161.gif"> </menuitem>
<Menu label = "menu 3">
<Menuitem label = "menu 3-1" icon = "http://www.bkjia.com/uploadfile/2012/0407/20120407090812492.gif" onclick = "alert ('this is menu 3-1 ');">
</Menuitem>
<Menu label = "menu 3-2">
<Menuitem label = "menu 3-2-1" icon = "http://www.bkjia.com/uploadfile/2012/0407/20120407090813196.gif" onclick = "alert ('here is menu 3-2-1 ');">
</Menuitem>
</Menu>
</Menu>
</Menu>

In this way, when you right-click <div>, the menu effect is as follows:


Note: currently, only Firefox supports <menu>. If you are interested, try Firefox.
 

Author: Xu mingxiang
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.