本文介绍了将键盘绑定到左/右导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一名摄影师,有一个网站,我无法编辑'模板'结构,但可以上传javascript / css等。
I am a photographer and have a website where I am unable to edit the 'template' structure but can upload javascript/css etc.
我想接下来绑定/ prev键盘右/左导航。
I want to bind next/prev navigation to keyboard right/left.
链接结构为:
<div class="image_navigation"> <h4>Image Navigation</h4> <ul> <li class="index"><a href="LINKURL">Index</a></li> <li class="previous"><a href="LINKURL">Previous</a></li> <li class="next"><a href="LINKURL">Next</a></li> </ul> </div>我提到 this 并设法创建它。
I referred to this and managed to create this.
$(function() {$(document).keyup(function(e) { switch(e.keyCode) { case 37 : window.location = $('li.prev').attr('href'); break; case 39 : window.location = $('li.next').attr('href'); break; }});});这是我被困的地方。它不起作用,因为它假定我正在引用一个href标签但引用包含它的li。
This is where I am stuck. It does not work because it assumes the I am refereing to a href tag but am refering to the li that contains it.
任何想法都会非常感激!
Any ideas would be much appreciated!
推荐答案window.location = $('li.next a').attr('href');
更多推荐
将键盘绑定到左/右导航
发布评论