使用须知
如何开始
安装
全局元素
样式重置
文字
颜色
徽章
提示框
表格
图标
栅格
原生组件
Panel
Accordion
Tabs
Layout
DataGrid
DataList
PropertyGrid
Tree
TreeGrid
LinkButton
Menu
MenuButton
SplitButton
SwitchButton
TabButton
Pagination
ProgressBar
SearchBox
Form
CheckBox
RadioBox
TextBox
PasswordBox
FileBox
TagBox
Combo
ComboBox
ComboGrid
ComboTree
ComboTreeGrid
ComboFilter
NumberBox
NumberSpinner
Calendar
DateBox
DateRangeBox
DateTimeBox
DateTimeRangeBox
TimeSpinner
DateTimeSpinner
Slider
ValidateBox
ImagesBox
Window
Dialog
Messager
Draggable
Droppable
Resizable
Tooltip
MaskedBox
扩展组件
头像
上传
时间轴
聊天
用户面板
消息面板
统计数据面板
Echart面板
圆形统计图
评论
相册
评分
文件
滚动条
二维码
条形码
天气
AT
编辑器
课程表
日程表
项目管理
客户管理
浏览器
FAQ
兼容插件
IconFont
Font Awesome
Ueditor
Ckeditor
Echarts
Plupload
Cropper
BaiduMap
AMap
Colpick
Nprogress
Gantt
GanttEditor
Raty
WebUploader
匿名
匿名 您还未登录

Menu

Document
Native
Basic
Custom Menu Item
Inline Menu
Menu Events
Keyboard Navigation
Plus
Extend

Keyboard Navigation in Menu

Press Alt+W to focus the menu. Once the menu get focus, you will be able to navigate menu using keyboard keys.

示例:

代码:

					
<div class="easyui-panel" title="Menu" style="width:150px;">
	<div id="mm" data-options="inline:true" style="width:100%">
		<div onclick="javascript:alert('new')">New</div>
		<div>
			<span>Open</span>
			<div style="width:150px;">
				<div><b>Word</b></div>
				<div>Excel</div>
				<div>PowerPoint</div>
				<div>
					<span>M1</span>
					<div style="width:120px;">
						<div>sub1</div>
						<div>sub2</div>
						<div>
							<span>Sub</span>
							<div style="width:80px;">
								<div>sub21</div>
								<div>sub22</div>
								<div>sub23</div>
							</div>
						</div>
						<div>sub3</div>
					</div>
				</div>
				<div>
					<span>Window Demos</span>
					<div style="width:120px;">
						<div>Window</div>
						<div>Dialog</div>
						<div>EasyUI</div>
					</div>
				</div>
			</div>
		</div>
		<div data-options="iconCls:'icon-save'">Save</div>
		<div data-options="iconCls:'icon-print',disabled:true">Print</div>
		<div class="menu-sep"></div>
		<div>Exit</div>
	</div>
</div>
<script type="text/javascript">
		(function($){
			function getParentMenu(rootMenu, menu){
				return findParent(rootMenu);

				function findParent(pmenu){
					var p = undefined;
					$(pmenu).find('.menu-item').each(function(){
						if (!p && this.submenu){
							if ($(this.submenu)[0] == $(menu)[0]){
								p = pmenu;
							} else {
								p = findParent(this.submenu);
							}
						}
					});
					return p;
				}
			}
			function getParentItem(pmenu, menu){
				var item = undefined;
				$(pmenu).find('.menu-item').each(function(){
					if ($(this.submenu)[0] == $(menu)[0]){
						item = $(this);
						return false;
					}
				});
				return item;
			}

			$.extend($.fn.menu.methods, {
				enableNav: function(jq, rootMenu){
					var firstItemSelector = '.menu-item:not(.menu-item-disabled):first';
					var lastItemSelector = '.menu-item:not(.menu-item-disabled):last';
					return jq.each(function(){
						var menu = $(this);
						rootMenu = $(rootMenu).length ? $(rootMenu) : menu;
						menu.attr('tabindex','0').css('outline','none').unbind('.menunav').bind('keydown.menunav', function(e){
							var item = $(this).find('.menu-active');
							switch(e.keyCode){
								case 13:  // enter
									item.trigger('click');
									break;
								case 27:  // esc
									rootMenu.find('.menu-active').trigger('mouseleave');
									break;
								case 38:  // up
									var prev = item.length ? item.prevAll(firstItemSelector) : menu.find(lastItemSelector);
									prev.trigger('mouseenter');
									return false;
								case 40:  // down
									var next = item.length ? item.nextAll(firstItemSelector) : menu.find(firstItemSelector);
									next.trigger('mouseenter');
									return false;
								case 37:  // left
									var pmenu = getParentMenu(rootMenu, menu);
									if (pmenu){
										item.trigger('mouseleave');
										var pitem = getParentItem(pmenu, menu);
										if (pitem){
											pitem.trigger('mouseenter');
										}
										pmenu.focus();
									}
									return false;
								case 39:  // right
									if (item.length && item[0].submenu){
										$(item[0].submenu).menu('enableNav', rootMenu).find(firstItemSelector).trigger('mouseenter');
										$(item[0].submenu).focus();
									}
									return false;
							}
						});
					});
				}
			});
		})(jQuery);

		$(function(){
			$('#mm').menu().menu('enableNav');
			$("#demo_region").keydown(function(e){
				if (e.altKey && e.keyCode == 87){
					$('#mm').focus();
				}
			})
		})
</script>