2012-11-26 36 views
0

我想使用jQuery中的history.js插件。代碼是:jQuery歷史和變量範圍

// Global 
var History = window.History; 
$(document).ready(function() { 
    History.Adapter.bind(window, 'statechange', function(){ 
    console.log('Yeeeeeeaah!'); 
    }); 
    window.History.pushState(null, null, '#42'); // Yeeeeeeaah! 
}); 
function anotherFunc() { 
    window.History.pushState(null, null, '#test'); // Nothing happens 
} 

範圍有什麼問題?

+0

嗯我不確定這個插件,但通常事件是調用'popstate' – devnull69

+2

你什麼時候調用anotherFunc()?是否在執行History.Adapter.bind之後? – rdamborsky

回答

0

您沒有執行anotherFunc

示波器沒有問題,但您可以省略var History = window.History並僅使用History