当按下某个键时,如何使用javascript加载新页面?

当按下某个键时,如何使用javascript加载新页面?,javascript,jquery,keydown,window.location,Javascript,Jquery,Keydown,Window.location,我有: 有什么想法吗 window.location = $('#nextPage').attr('href'); 下面是一个演示: 您还可以访问以下链接之一的href属性,以加快执行速度: $(document).on('keydown', function (event) {alert(event.type); if (event.which == 37) { $('#prevPage').trigger('click'); //or

我有:

有什么想法吗

window.location = $('#nextPage').attr('href');
下面是一个演示:

您还可以访问以下链接之一的
href
属性,以加快执行速度:

$(document).on('keydown', function (event) {alert(event.type);
    if (event.which == 37) {
        $('#prevPage').trigger('click');
        //or
        window.location = $('#prevPage').attr('href');
    } else if (event.which == 39) {
        $('#nextPage').trigger('click');
        //or
        window.location = $('#nextPage').attr('href');
    }
});​

您想使用onkeypress事件


描述如何使用此事件,并为您需要的任何按钮提供键码生成器。

阅读当我按下箭头键时,我希望我的浏览器在浏览器窗口中滚动页面。@Yaypaul-他询问的是按键,而不是鼠标单击。如果逻辑上是下一页,您应该给锚定一个(
),这将允许您使用
$('[rel=“next”]')获取下一个位置。attr('href')或者当然,你可以等待某人添加一个完整的免费示例,但什么也学不到。。。
$(document).on('keydown', function (event) {alert(event.type);
    if (event.which == 37) {
        $('#prevPage').trigger('click');
        //or
        window.location = $('#prevPage').attr('href');
    } else if (event.which == 39) {
        $('#nextPage').trigger('click');
        //or
        window.location = $('#nextPage').attr('href');
    }
});​
window.location = document.getElementById('nextPage').href;