我有一些像這樣的鏈接的頁面: test1.htmlHREF到頁面+變化類名的.js文件一次
<div>
<a href="test2.html">Go to TAB1</a>
<a href="test2.html">Go to TAB2</a>
</div>
的第二頁是用標籤頁: test2.html
<div id="tab1" class="active-content">
<p>Hello this is the first TAB</p>
</div>
<div id="tab2" class="content">
<p>Hello this is the second TAB</p>
</div>
我需要做的是,當我點擊Go to TAB2
HREF,更改爲test2.html
頁面,改變它的DIV CL屁股,所以他們看起來像這樣:(爲了顯示頁面加載時的第二個選項卡)。
<div id="tab1" class="content">
<p>Hello this is the first TAB</p>
</div>
<div id="tab2" class="active-content">
<p>Hello this is the second TAB</p>
</div>
我試圖使用javascript href="javascript:tab()"
但我不能同時做兩件事情。頁面更改爲test2.html
,但在頁面加載之前運行代碼。
function tab(){
window.location.href='test2.html';
var element = document.getElementById("tab1");
element.className="content";
var element = document.getElementById("tab2");
element.className="active-content";
}
我嘗試使用setTimeout
或onload
方法,但一無所獲。 我需要更改爲test2.html並更改爲第二個選項卡,只需單擊href,我該如何執行此操作?
嘗試使用類似'test2.html#tab1'的URL,並讓你的'onload'方法檢查'document.location.hash'。 – Barmar 2013-04-23 09:27:29
我嘗試過使用'test2.html#tab2',但是轉到了#tab1,這是一個墮落者。我不能把'onload加到#tab2'上,因爲我也想用第一個鏈接出現tab1 – Flowen 2013-04-23 09:29:11