我正在做一個畫廊,並試圖找出如何編程箭頭鍵導航畫廊。下一個點擊鍵按
因此,按下左箭頭會去到以前的圖片網址:
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
謝謝大家的意見。他們都幫助。 –