私は Javascript プログラマーではありませんが、タブ領域を作成する方法を見つけました (つまり、タブをクリックすると別の DIV コンテンツが表示されます) が、私のコードは非常に大きく見えます。誰かがそれをいくらか凝縮する方法について教えてくれるかどうか疑問に思っていました.
HTMLは次のとおりです。
<aside id="sb-popular">
<p class="sb-popular-nav">
<a id="sbpt1" class="current" href="javascript:showdiv('sbp-latest'); hidediv('sbp-commented'); hidediv('sbp-popular'); hidediv('sbp-views'); tabset('sbpt1'); taboff('sbpt2'); taboff('sbpt3'); taboff('sbpt4');">Latest</a>
<a id="sbpt2" href="javascript:showdiv('sbp-commented'); hidediv('sbp-latest'); hidediv('sbp-popular'); hidediv('sbp-views'); tabset('sbpt2'); taboff('sbpt1'); taboff('sbpt3'); taboff('sbpt4');">Commented</a>
<a id="sbpt3" href="javascript:showdiv('sbp-popular'); hidediv('sbp-commented'); hidediv('sbp-latest'); hidediv('sbp-views'); tabset('sbpt3'); taboff('sbpt1'); taboff('sbpt2'); taboff('sbpt4');">Popular</a>
<a id="sbpt4" href="javascript:showdiv('sbp-views'); hidediv('sbp-commented'); hidediv('sbp-popular'); hidediv('sbp-latest'); tabset('sbpt4'); taboff('sbpt2'); taboff('sbpt3'); taboff('sbpt1');">Views</a>
</p>
<div id="sbp-latest">
Content here
</div>
<div id="sbp-commented">
Content here
</div>
<div id="sbp-popular">
Content here
</div>
<div id="sbp-views">
Content here
</div>
</aside>
ご覧のとおり、javascript は少し扱いにくいです。これが私のJSです。
function hidediv(d) { document.getElementById(d).style.display = "none"; }
function showdiv(d) { document.getElementById(d).style.display = "block"; }
function tabset(d) { document.getElementById(d).style.color = "white";}
function taboff(d) { document.getElementById(d).style.color = "black";}