jquery keyboard turns pages left and right, jquery keyboard direction keys page turning function, when there is no previous or next article, there will be no response when pressing the keyboard to avoid wrong jumps.
HTML code
<p>上一篇:<a id='pre' href='http://www.daimajiayuan.com/sitejs-17294-1.html'>一款随滚动条下滑左右渐入的页面布局</a> </p> <p>下一篇:<a id='next' href='http://www.daimajiayuan.com/sitejs-18339-1.html'>点击复选框添加或删除value值到input输入框中</a> </p>
jquery code
$(document).ready(function(){ var prevpage=$("#pre").attr("href"); var nextpage=$("#next").attr("href"); $("body").keydown(function(event){ if(event.keyCode==37 && prevpage!=undefined) location=prevpage; if(event.keyCode==39 && nextpage!=undefined) location=nextpage; }); });
The above is the entire content of this article, I hope you all like it.