Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript键盘导航_Javascript_Navigation_Keyboard - Fatal编程技术网

javascript键盘导航

javascript键盘导航,javascript,navigation,keyboard,Javascript,Navigation,Keyboard,我是javascript新手,我正在尝试向我的站点添加一个脚本,允许用户使用键盘导航到每个页面。到目前为止,我还没能让它发挥作用。以下是我得到的: function addListener(element, type, response) { if (element.addEventListener) { element.addEventListener(type, response, false); } else if (element.attachEv

我是javascript新手,我正在尝试向我的站点添加一个脚本,允许用户使用键盘导航到每个页面。到目前为止,我还没能让它发挥作用。以下是我得到的:

function addListener(element, type, response) {
    if (element.addEventListener) {
        element.addEventListener(type, response, false);
    }
    else if (element.attachEvent) {
        element.attachEvent("on" + type, response);
    }
}

addListener(window, "keypress", function(key) {
    // do this stuff when a key is pressed:

    key = key || window.event;
    var theKey = key.which || key.keyCode;

    switch (theKey) {
    // if they hit a
    case 65 :
        window.location.href = "/about.html";
        break;
    // if they press r
    case 82 :
        window.location.href = "/resources.html";
        break;
        // if they hit l
    case 76 :
        window.location.href = "/links.html";
        break;
    // if they press h
    case 72 :
        window.location.href = "/index.html";
        break;
    }
});
您不使用()[Access Key]的任何原因?对于非可视用户代理,这些工具的优点是可以很好地与UI配合使用。