0

我想问当用户按下箭头键时如何更改网页,就像漫画/书籍的网络如果我们想要下一页我们只需按下箭头键

对不起我的英语,谢谢

4

3 回答 3

1

Here is a non jQuery option:

document.onkeydown = arrowChecker;

function arrowChecker(e) {  
    e = e || window.event;
    if (e.keyCode == '37') { //left
        document.location.href = "http://stackoverflow.com/";
    }
    else if (e.keyCode == '39') { //right
       document.location.href = "http://google.com/";
    }
}
于 2013-11-07T12:04:21.203 回答
1

您可以为此使用 jQuery:

$(document).keydown(function(e) {
    if (e.which == 37) { 
       alert("left");
       e.preventDefault();
       return false;
    }

    if (e.which == 39) { 
       alert("right");
       e.preventDefault();
       return false;
    }
});
于 2013-11-07T11:52:40.853 回答
1

如果您想使用 jQuery 框架,请查看JS/jQuery 中的绑定箭头键

在普通的 javascript 中,我将使用:

document.onkeydown = function (e) { 
  e = e || window.event; 
  var charCode = (e.charCode) ? e.charCode : e.keyCode;

  if (charCode == 37) {
        alert('left');
  }
  else if (charCode == 39) {
    alert('right');
  }
};
于 2013-11-07T12:02:21.333 回答