KeyBoard使用jquery导航菜单 [英] KeyBoard Navigation for menu using jquery

查看:123
本文介绍了KeyBoard使用jquery导航菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将键盘导航添加到菜单(基于
的ul li),我已将keydown事件绑定到菜单(或者我应该将keydown绑定到文档?)

I am trying to add keyboard navigation to Menu(ul li based ) , i have bound the keydown event to menu (or should i bind keydown to the document ?)

使用的处理函数如下:

 KeyDown: function(e) {        

    var toFocus = false;


                  if (e.keyCode == 38) {
         toFocus = $((e.target/* li */).next()[0]);
      }
                          if (e.keyCode == 40) {
         toFocus = $((e.target).next()[1]);
      }
    if (toFocus) {
        $(e.target).attr('tabIndex', '-1');
        $(toFocus).attr('tabIndex', '0');
        toFocus.focus();
        return false;
        }
        }

这里我得到 e.target为html 代替li?

你可以建议任何其他方式添加键盘导航吗?

can u suggest any other way to add keyboard navigation ?

推荐答案

我只是想知道,为什么不使用现有的插件,而不是自己这样做?

I just wonder if, instead of doing this by your self, why not using an already existing plugin?


jQuery键盘导航

演示此处页面


我的演示:只需添加示例页面示例

这篇关于KeyBoard使用jquery导航菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆