我在我正在開發的網站上有一個選項卡式部分,並且希望爲每個選項卡啓用唯一的URL以及歷史記錄支持。jQuery地址/深層鏈接問題
看來jQuery地址插件是要走的路,但我在實施時遇到了麻煩。我可以分配網址並更改地址欄。後退按鈕遍歷URL,但實際上並沒有改變標籤。
地址文檔不是很好。我假設我錯過某種事件監聽器,但我不知道如何初始化它或應用它。
這裏是我的JS
$('.sm-tab').click(function() {
$.address.value($('a', this).attr('href'));
smReset();
$('#sm-tabs').find('.active').each(function() {
$(this).removeClass('active');
$(this).addClass('inactive');
});
$(this).removeClass('inactive');
$(this).addClass('active');
var smClassArray = $(this).attr('class').split(" ");
var smDivClass = smClassArray[1];
$('#'+smDivClass).show();
});
我的HTML看起來像這樣
<div id="sm-tabs">
<div class="sm-tab inactive twitter">
<span class="twitter sprite-sm-twitter"><a href="?tab=twitter" class="hidetext">Twitter</a></span>
</div>
<div class="sm-tab inactive youtube">
<span class="youtube sprite-sm-youtube"><a href="?tab=youtube" class="hidetext">YouTube</a></span>
</div>
</div>
<div id="sm-widgets">
<div id="twitter">
Content
</div>
<div id="youtube">
Content
</div>
</div>
請參閱:http://stackoverflow.com/questions/172957/detecting-back-button-hash-change-in-url –