0
我在我的網站上有這個內容框,它有不同的標籤,當你點擊其中一個標籤時,它使用JS來隱藏/顯示內容中的相應div框。問題w/window.location.hash
我也有這個在我的頭給每個DIV內容框裏面它自己的網址:
<script type="text/javascript">
function loadSmugInfo() {
if(window.location.hash == '#smuginfo')
document.getElementById('contentInfo').style.display = "block";
document.getElementById('contentSlideshow').style.display = "none"
}
</script>
<script type="text/javascript">
function loadFind() {
if(window.location.hash == '#find')
document.getElementById('contentMap').style.display = "block";
document.getElementById('contentSlideshow').style.display = "none"
}
</script>
<script type="text/javascript">
function loadSmugmug() {
if(window.location.hash == '#smugmug')
document.getElementById('contentSmugInfo').style.display = "block";
document.getElementById('contentSlideshow').style.display = "none"
}
</script>
<script type="text/javascript">
function loadMain() {
if(window.location.hash == '#')
document.getElementById('contentSlideshow').style.display = "block"
}
</script>
<script type="text/javascript">
function loadSlideshow() {
if(window.location.hash == '#slideshow')
document.getElementById('contentSlideshow').style.display = "block"
}
</script>
我也有它所以當你點擊一個標籤,它改變了哈希值。
這是我的問題。 當頁面像普通(沒有散列)一樣加載時,第一個和最上面的div仍然不顯示(即使它設置爲在CSS中顯示:block)。
我正在加載上面看到的函數,在內容框上方的圖像上使用onLoad。
任何幫助將不勝感激,我有點緊張的時間表。 讓我知道你是否需要更多信息。 謝謝!
旁邊的問題:你爲什麼要用se爲每個功能分配'
這裏有幾個問題。
首先,你不顯示任何方式調用這些函數。您可能想要啓動間隔計時器來輪詢這些函數並定期檢查它們。這將確保他們在頁面加載時進行評估,並且每次散列更改。
您還在評估散列==「#」是否爲默認值,但不會在初始頁面加載時顯示。也許把一個AND調查,以檢查它是否==「」以及。
這是我用於散列輪詢的一些代碼示例。也許它可以幫助。
來源
2011-10-11 18:52:58
試試這個:
來源
2014-07-24 17:11:33 resul