2010-11-29 70 views
0

當我使用hashchange jQuery插件從http://benalman.com/projects/jquery-hashchange-plugin/掛鉤的事件時,窗口的location.hash變化獲取當前哈希值。Hashchange jQuery插件 - 點擊錨

我想在散列更改時通過新散列值(使用event.fragment獲得)和當前散列值(即將觸發事件之前的值)來觸發函數。

這裏是想什麼,我實現了文檔片斷:

$(window).bind('hashchange', function(event){ 
    myFunction(event.fragment, /* currentHash */); 
}); 

這可能嗎?

在此先感謝。

回答

2

有位置上的屬性:

$(window).bind('hashchange', function(event){ 
    myFunction(event.fragment, location.hash); 
}); 

或者,自己保存它:

var lastHash = location.hash;     //set it initially 
$(window).bind('hashchange', function(event){ 
    myFunction(event.fragment, hashLash);  //previous hash 
    lastHash = location.hash;     //update it 
});