jQuery EasyUI Menu and Button Plugin - Menu
jQuery EasyUI Plugins
Override the defaults through $.fn.menu.defaults.
A Menu is usually used as a context menu. It is the foundational component for creating other menu components (such as menubutton and splitbutton). It can also be used for navigation and executing commands.
Usage
Creating a Menu
To create a menu from markup, the 'easyui-menu' class should be added to
Create a menu programmatically and listen for the 'onClick' event.
$('#mm').menu({
onClick:function(item){
//...
}
});
Showing a Menu
When a menu is created, it is hidden and invisible. Call the 'show' method to display the menu.
$('#mm').menu('show', {
left: 200,
top: 100
});
Menu Items
A menu item represents an individual item displayed in a menu. It contains the following properties:
| Name | Type | Description | Default value |
|---|---|---|---|
| id | string | The id attribute of the menu item. | |
| text | string | The item text. | |
| iconCls | string | A CSS class for displaying a 16x16 icon on the left of the item. | |
| href | string | Sets the page location when the menu item is clicked. | |
| disabled | boolean | Defines whether the menu item is disabled. | false |
| onclick | function | The function called when the menu item is clicked. |
Menu Properties
| Name | Type | Description | Default value |
|---|---|---|---|
| zIndex | number | The z-index style of the Menu, from which incrementing starts. | 110000 |
| left | number | The left position of the Menu. | 0 |
| top | number | The top position of the Menu. | 0 |
| minWidth | number | The minimum width of the Menu. This property is available since version 1.3.2. | 120 |
| hideOnUnhover | boolean | If set to true, the menu is hidden automatically when the mouse leaves it. This property is available since version 1.3.5. | true |
Menu Events
| Name | Parameters | Description |
|---|---|---|
| onShow | none | Triggered after the menu is shown. |
| onHide | none | Triggered after the menu is hidden. |
| onClick | item | Triggered when a menu item is clicked. The example below shows how to handle all menu item clicks: |
Menu Methods
| Name | Parameters | Description |
|---|---|---|
| options | none | Return the options object. |
| show | pos | Shows the menu at the specified position. |
pos 参数有两个属性:
left:新的左边位置。
top:新的顶部位置。 |
| hide | none | Hides the menu.| onSelect | event | destroy | none | Destroys the menu.| onSelect | event | getItem | itemEl | Gets the properties of the menu item containing the 'target' property (indicating the item DOM element). The example below shows how to get a specified item by id:
| onSelect | event | setText | param | Sets the text for the specified menu item. The 'param' parameter contains two properties:var itemEl = $('#m-open')[0]; // the menu item element var item = $('#mm').menu('getItem', itemEl); console.log(item);
target: the DOM object, the menu item to be set.
text: string, the new text value.
代码实例:
var item = $('#mm').menu('findItem', 'Save'); $('#mm').menu('setText', { target: item.target, text: 'Saving' });| onSelect | event | setIcon | param | Set the icon for the specified menu item (menu item). The 'param' parameter contains two properties:
target: the DOM object, that is, the menu item.
iconCls: the CSS class of the new icon.
代码实例:
$('#mm').menu('setIcon', { target: $('#m-open')[0], iconCls: 'icon-closed' });| onSelect | event | findItem | text | Finds the specified menu item. The returned object is the same as that returned by the getItem method.
Code example:
// find 'Open' item and disable it
var item = $('#mm').menu('findItem', 'Open');
$('#mm').menu('disableItem', item.target);
| onSelect | event | appendItem | options | Appends a new menu item. The 'param' parameter indicates the properties of the new item. By default, the new item is added as a top-level menu item. To append a submenu item, set the 'parent' property to indicate the parent item that already has subitems.
Code example:
// append a top menu item
$('#mm').menu('appendItem', {
text: 'New Item',
iconCls: 'icon-ok',
onclick: function(){alert('New Item')}
});
// append a menu separator
$('#mm').menu('appendItem', {
separator: true
});
// append a sub menu item
var item = $('#mm').menu('findItem', 'Open'); // find 'Open' item
$('#mm').menu('appendItem', {
parent: item.target, // the parent item element
text: 'Open Excel',
iconCls: 'icon-excel',
onclick: function(){alert('Open Excel')}
});
| onSelect | event | removeItem | itemEl | Remove the specified menu item (menu item).| onSelect | event | enableItem | itemEl | Enable the menu item (menu item).| onSelect | event | disableItem | itemEl | Disable the menu item (menu item). |
jQuery EasyUI Plugins