-1
我想將var loadurl傳遞給上面的函數。我怎樣才能做到這一點? (下面的代碼是我的功能,我想ID傳遞給上面的代碼任何幫助表示讚賞History.JS將var傳遞給上述函數
$(函數(){
// Prepare
var History = window.History; // Note: We are using a capital H instead of a lower h
if (!History.enabled) {
// History.js is disabled for this browser.
// This is because we can optionally choose to support HTML4 browsers or not.
return false;
}
// Bind to StateChange Event
History.Adapter.bind(window,'statechange',function() { // Note: We are using statechange instead of popstate
var State = History.getState();
console.log(loadurl);
$('#test').load(loadurl);
/* Instead of the line above, you could run the code below if the url returns the whole page instead of just the content (assuming it has a `#content`):
$.get(State.url, function(response) {
$('#content').html($(response).find('#content').html()); });
*/
});
// Capture all the links to push their url to the history stack and trigger the StateChange Event
$('a').click(function(evt) {
evt.preventDefault();
var loadurl = $(this).attr('id');
History.pushState(loadurl, $(this).text(), $(this).attr('onclick'));
});
});