gpt4 book ai didi

javascript - 下一步点击按键

转载 作者:行者123 更新时间:2023-11-29 18:25:35 25 4
gpt4 key购买 nike

我正在制作一个画廊,并试图弄清楚如何对箭头键进行编程以在画廊中导航。

因此,按向左箭头将转到上一个图像 url:

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";
}
});

最佳答案

基本上你需要让 body 标签有一个按键事件(或者使用 jquery 来做一个事件监听器)然后只检查键码(左箭头是 37,右箭头是 39)然后使用 window.location 来重定向页面。 All Key Codes

<head>
<script>
function e(event){
if(event.keyCode == 37){
//Left Arrow Pushed
window.location = "../prevphoto.php";
}else if(event.keyCode == 39){
//Right Arrow Pushed
window.location = "../nextphoto.php";
}
}
</script>
</head>
<body onKeyPress="e(event)" >

</body>​

关于javascript - 下一步点击按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13756285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com