帝國CMS模板中實現鍵盤翻頁的教程
功能需求:
1、方向鍵左、右鍵實現打開上一篇、下一篇
2、回車鍵返回欄目目錄。
解決方案:
將以下代碼放置于內容頁模板底部。
- <script type="text/javascript">
- document.onkeydown=pageEvent;
- var prevpage="[!--news.url--]e/public/GotoNext/?enews=pre&classid=[!--classid--]&id=[!--id--]";
- var nextpage="[!--news.url--]e/public/GotoNext/?enews=next&classid=[!--classid--]&id=[!--id--]";
- var listpage="[!--class.url--]";
- function pageEvent(evt){
- evt=evt||window.event;
- var key=evt.which||evt.keyCode;
- if(key==13) location=listpage;
- if(key==37) location=prevpage;
- if(key==39) location=nextpage;
- };
- </script>
新聞熱點
疑難解答