支持键盘方向键等按键的页面翻页跳转效果
<? $n_id=$_GET['ID']; $rs3=new COM("adodb.recordset"); $rs3->open("select top 1 * from [products2] where [id]<$n_id order by id desc",$conn,1,1); if(! $rs3->eof) { echo "上一篇:<a href='?ID=".$rs3->Fields(id)->value."'>".$rs3->Fields(title)->value."</a>"; $prevpage="?ID=".$rs3->Fields(id)->value.""; } else { echo "没有上一篇了"; } ?> <BR> <? $rs2=new COM("adodb.recordset"); $rs2->open("select top 1 * from [Products2] where [id]>$n_id order by id asc",$conn,1,1); if(! $rs2->eof) { echo "下一篇:<a href='?ID=".$rs2->Fields(id)->value."'>".$rs2->Fields(title)->value."</a>"; $nextpage="?ID=".$rs2->Fields(id)->value.""; } else { echo "没有下一篇了"; } ?>
<script language=javascript> document.onkeydown=nextpage var prevpage="<?=$prevpage?>" //向左 var nextpage="<?=$nextpage?>" //向右 //var bookpage="http://www.aa25.cn" //回车 function nextpage(event) { event = event ? event : (window.event ? window.event : null);
//if (event.keyCode==13) location=bookpage;//回车 if (event.keyCode==37) location=prevpage;//向左 if (event.keyCode==39) location=nextpage;//向右 //if (event.ctrlKey && event.keyCode==13) {alert("你点了 ctrl + enter ,现在转向到 标准之路."); location="http://www.aa25.cn";} //同时按下键盘多个键的事件情况 } </script>
|