2011-04-27 59 views
0

我有燒烤插件已經工作,所以這只是一個表面上的變化。我不知道如何將URL從/index.html#pages/index.html轉換爲/index.html#index片段URL轉換

它基本上是一個片段轉換,但我對JS很陌生。有什麼想法嗎?

回答

1

您可以使用window.location.hash訪問哈希,並返回一個字符串,以便您可以對其進行任何字符串操作。例如:

var temp = window.location.hash; // == #pages/index.html 
temp = temp.replace("pages/","").replace(".html",""); 
window.location.hash = temp; //sets the hash to #index 
+0

@Pepe您是否設置了'hashchange'事件? – cem 2011-04-28 00:36:13

+0

你可以。這只是操縱哈希的代碼。在你的問題中你沒有提到改變?如果是這樣,你應該解釋你想如何使用它。我找到了關於onhashchange的一些信息,我可以改變我的答案,一旦我知道你的期望,就將它包括進去。它看起來像jQuery有一個很好的onhashchange事件。這裏的一些信息 - http://stackoverflow.com/questions/680785/on-window-location-hash-change – LeRoy 2011-04-28 13:11:44