This example demonstrates how to set MenuItem configuration properties when adding items to a Menu instance.
Note: By default clicking outside of a Menu instance will hide it. Additionally, MenuItem instances without a submenu or a URL to navigate to will hide their parent Menu instance when clicked. Click the "Show Menu" button below to make the Menu instance visible if it is hidden.
A MenuItem has a number of configuration
properties that affect its behavior and visual rendering. Any of these
configuration properties can be set when adding an item to its parent Menu
instance by defining them in an object that is passed to the Menu's
addItem
, insertItem
, or addItems
methods. This example ulitizes the following configuration properties:
text, selected, disabled, url, and checked.
1 | /* |
2 | Instantiate a Menu: The first argument passed to the |
3 | constructor is the id of the element in the page |
4 | representing the Menu; the second is an object literal |
5 | of configuration properties. |
6 | */ |
7 | |
8 | var oMenu = new YAHOO.widget.Menu("basicmenu", { fixedcenter: true } ); |
9 | |
10 | |
11 | /* |
12 | Add items to the Menu instance by passing an array of object literals |
13 | (each of which represents a set of YAHOO.widget.MenuItem |
14 | configuration properties) to the "addItems" method. |
15 | */ |
16 | |
17 | oMenu.addItems([ |
18 | |
19 | { text: "Selected MenuItem", selected: true }, |
20 | { text: "Disabled MenuItem", disabled: true }, |
21 | { text: "MenuItem With A URL", url: "http://www.yahoo.com" }, |
22 | { text: "Checked MenuItem", checked: true } |
23 | |
24 | ]); |
25 | |
26 | |
27 | /* |
28 | Since this Menu instance is built completely from script, call the |
29 | "render" method passing in the DOM element that it should be |
30 | appended to. |
31 | */ |
32 | |
33 | oMenu.render("rendertarget"); |
view plain | print | ? |
Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings