AJAX -- 使用 jQuery.history 解決「上一頁」問題
AJAX簡介方法jQueryREST問與答上一頁問題搜尋問題訊息相關網站參考文獻最新修改簡體版English |
使用 jQuery Plugin<script type="text/javascript" src="jquery.history.js"></script> ... <script type="text/javascript"> // 「上一頁」觸發後執行的函數 function pageload(hash) { // 根據傳回的 hash(錨點),AJAX 置換顯示的內容 if(hash) { // 重新讀取指定頁面 $("#load").load(hash + ".html"); } else { // 如果沒有回傳值,代表已經回到 AJAX 的初始狀態頁,清空顯示的內容 $("#load").empty(); } } $(function () { // 初始化 history plugin,並設定回傳使用的函數 $.historyInit(pageload); // 設定觸發寫入歷史紀錄條件的按鈕事件 $("a[rel='history']").click(function(){ // 取得超連結的錨點 var hash = this.href; hash = hash.replace(/^.*#/, ''); // 點選 AJAX 頁面時,紀錄位置於瀏覽器的歷史紀錄中 $.historyLoad(hash); return false; }); }); </script> 參考文獻
|
page revision: 0, last edited: 03 Dec 2010 00:53
Post preview:
Close preview