我正在做一个画廊,并试图找出如何编程箭头键导航画廊。下一个点击键按
因此,按下左箭头会去到以前的图片网址:
function window.location = 'http://www.example.com/prevphoto.php';
按右箭头会去到下一个图像的URL。
function window.location = 'http://www.example.com/nextphoto.php';
更新(感谢Haxxed指着我在正确的方向) 这是我在哪里,但它不工作。你能明白为什么吗?
$('body').keypress(function (e) {
if (e.which == 37) {
// Left Arrow Pushed
window.location = "/prevphoto.php";
} else if (e.which == 39) {
// Right Arrow Pushed
window.location = "/nextphoto.php";
}
});
向我们展示一些代码或发布jsFiddle。 – glortho
谢谢大家的意见。他们都帮助。 –