我有一些这样的链接页面: test1.html
<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 类,使它们看起来像这样:(为了在页面加载时显示第二个 TAB)。
<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
oronload
方法但没有。我需要更改为 test2.html 并更改为第二个选项卡,只需单击一个 href,我该怎么做?