次のようなリンクを含むページがあります: test1.html
<div>
<a href="test2.html">Go to TAB1</a>
<a href="test2.html">Go to TAB2</a>
</div>
2 番目のページはタブ付きのページです: 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 クラスを次のように変更することです (ページの読み込み時に 2 番目のタブを表示するため)。
<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()"
ましたが、一度に 2 つのことを行うことはできません。ページは に変わります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 をクリックするだけで 2 番目の TAB に変更する必要があります。これを行うにはどうすればよいですか?