AJAX -- jQuery.history 的完整範例

AJAX

簡介

方法

jQuery

REST

問與答

上一頁問題

搜尋問題

訊息

相關網站

參考文獻

最新修改

簡體版

English

專案下載:jqhistory.zip

網頁:jqhistory.htm

<html> 
<head> 
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
  <title>jQuery History Plugin Ajax Sample</title> 
  <script type="text/javascript" src="jquery.js"></script> 
  <script type="text/javascript" src="jquery.history.js"></script> 
  <script type="text/javascript" src="ajax.js"></script> 
  <style type="text/css">
    #content { border: 1px #666 solid; width: 300px; height: 300px; padding:0.5em; }
  </style> 
</head> 
<body> 
  <h1>jQuery History Plugin Ajax Sample</h1> 
  <div id="ajax-links"> 
    <ul> 
      <li><a href="#1">load 1.html</a></li> 
      <li><a href="#2">load 2.html</a></li> 
      <li><a href="#3">load 3.html</a></li> 
    </ul> 
    <div id="content"></div> 
    <hr /> 
  </div> 
  <p>[<a href="../">All samples</a>] 
      [<a href="http://github.com/tkyk/jquery-history-plugin">Project home</a>]
  </p> 
</body> 
</html>

程式:ajax.js

jQuery(document).ready(function($) {
        function load(num) {
            $('#content').load(num +".html");
        }
 
        $.history.init(function(url) {
                load(url == "" ? "1" : url);
            });
 
        $('#ajax-links a').live('click', function(e) {
                var url = $(this).attr('href');
                url = url.replace(/^.*#/, '');
                $.history.load(url);
                return false;
            });
    });

說明:jQuery(function($) 的意義。

Example: Uses both the shortcut for $(document).ready() and the argument to write failsafe jQuery code using the $ alias, without relying on the global alias.

jQuery(function($) {
  // Your code using failsafe $ alias here...
});

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License