利用键盘的code值;然后进行判断即可;思路很简单

 

HTML+CSS代码如下

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
/*页脚的标注*/
.broszhu{margin: 90px 0 0 30px;}
#home_top {height: 48px;line-height:48px;font-size:18; text-align: center; color:#008CD7;}
#home_bottom {color:#008CD7;text-align:center;font-size:14px;}
</style>
</head>
<body>
<p>说明:按键盘← →方向键 或 PageUp PageDown键直接翻页</p>
<p>向左 回到我的博客首页,向右 可以去百度首页</p>
<p>代码很简单,就是基础的东西应用</p>
<br/>
document.onkeydown = chang_page;
<br/>
function chang_page() {
<br/>
if (event.keyCode == 37 || event.keyCode == 33) {location = 'http://taobao.fm/';}
<br/>
if (event.keyCode == 39 || event.keyCode == 34) {location = 'https://www.baidu.com/';}
<br/>
}
<div class="broszhu">
<h3 id="home_top">按键盘← →方向键翻页 - Powered By
<a href="http://taobao.fm/"target="_blank">broszhu</a>
  博客网址:<a href="http://taobao.fm/" target="_blank">taobao.fm</a>
</h3>
<p id="home_bottom">学习JavaScript是一件很有趣的事,可以做出很多自豪的小玩意!--broszhu (这个页面是实现原理:<a href="#" target="_blank">点此查看</a></p>
</div>
</body>
</html>

 

JavaScript代码如下:

<script>
document.onkeydown = chang_page;
function chang_page() {
if (event.keyCode == 37 || event.keyCode == 33) {location = 'http://taobao.fm/';}
if (event.keyCode == 39 || event.keyCode == 34) {location = 'https://www.baidu.com/';}
}
</script>