如何获取键盘上的箭头键以触发博客中的导航(上一页/下一页)链接

我到目前为止拼凑在一起的脚本看起来像这样:

 /* KEYNAV */ document.onkeydown = function(e) { if (! e) var e = window.event; var code = e.charCode ? e.charCode : e.keyCode; if (! e.shiftKey && ! e.ctrlKey && ! e.altKey && ! e.metaKey) { if (code == Event.KEY_LEFT) { if ($('previous_page_link')) location.href = $('previous_page_link').href; } else if (code == Event.KEY_RIGHT) { if ($('next_page_link')) location.href = $('next_page_link').href;} } });  

我的HTML看起来像这样:

 

{block:PreviousPage} PREVIOUS PAGE {/block:PreviousPage} {block:NextPage} NEXT PAGE {/block:NextPage}

https://stackoverflow.com/questions/2259690/how-to-get-the-arrow-keys-on-the-keyboard-to-trigger-navigation-previous-next-p/{PreviousPage} / https://stackoverflow.com/questions/2259690/how-to-get-the-arrow-keys-on-the-keyboard-to-trigger-navigation-previous-next-p/{NextPage}代码表示不同的动态页面链接,具体取决于您所在的页面。 这个特殊问题特定于tumblr,但通常也是如此:

有没有办法让我的左右箭头键触发这些动态链接?

感谢您的阅读,非常感谢您对此的任何帮助。

 function leftArrowPressed() { // Your stuff here } function rightArrowPressed() { // Your stuff here } document.onkeydown = function(evt) { evt = evt || window.event; switch (evt.keyCode) { case 37: leftArrowPressed(); break; case 39: rightArrowPressed(); break; } }; 

用它来告诉你keyIdentifier属性 宾语。

        

然后,您可以使用if-then逻辑忽略您不感兴趣的所有按键,并将正确的行为连接到您的行为。

以下内容将左右箭头键分配给您的链接(基于锚点/链接元素的ID)。

       

Google Yahoo