2010-05-16 61 views
2

這裏<現場演示 - http://webcallonline.exoflux.co.uk/html/jQuery動態頁面加載不會工作,不知道爲什麼有什麼想法?

$(function() { 
var url = $(this).attr("href"); 
    $("nav").delegate("a", "click", function(event) { 
    event.preventDefault(); 
     window.location.hash = $(this).attr('href'); 
     $("#main").slideUp('slow', function(){ 
     $("#main").load(url + " #main", function() 
     { 
     $("#main").slideDown('slow'); 
     }); 
     }); 

    }); 

    $(window).bind('hashchange', function(){ 
    newHash = window.location.hash.substring(1); 
    }); 

    $(window).trigger('hashchange'); 
}); 

有沒有人有什麼想法?

回答

1

這條線:

var url = $(this).attr("href"); 

應該單擊處理內部移動:

$("nav").delegate("a", "click", function(event) { 
    var url = $(this).attr("href"); 
    event.preventDefault(); 

因爲你是基於點擊的錨的href加載內容。

編輯:或者你打算得到當前的網址?

var url = window.location.href; 

+0

Thankyou karim79,你的第一個建議修正了:)任何人有任何想法現在如何使頁面加載動態時按下後退按鈕? – Luke 2010-05-16 16:54:32

相關問題