|
預實現效果:(點擊不同的tab顯示不同面板內容)
一:用到的js函數:
復制代碼 代碼如下:
<script language="Javascript" type="text/Javascript" >
//變換tab函數
//原則,外層div里含有內層多個div
function tabPanelEx(trThis,urlImgNormal,urlImgPoint,tabs,tabid){
var tds=trThis.parentNode.children;
for(var i=0;i<tds.length;i++)
{
if(tds[i].attributes["ex"])
{
tds[i].style.backgroundImage="url("+urlImgNormal+")";
}
}
trThis.style.backgroundImage="url("+urlImgPoint+")";
//div control
var vtabs=document.getElementById(tabs).children;
for(var j=0;j<vtabs.length;j++)
{
vtabs[j].style.display="none";
}
document.getElementById(tabid).style.display="block";
}
</script>
二:頁面調用代碼;
代碼
復制代碼 代碼如下:
<table width="768" border="0" cellspacing="0" cellpadding="0">
<!-- tab上方按鈕行 -->
<tr valign="bottom">
<td height="37" background="../images/a_06.jpg">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16" height="32" valign="bottom"></td>
<td ex="true" width="94" height="32" align="right" valign="middle" background="../images/an_01.jpg" style="cursor:pointer"
onClick="tabPanelEx(this,'../images/an_02.jpg','../images/an_01.jpg','newTabs','newsTab1')">
<div style="width:72px;height:28px;line-height:28px;text-align:left;" class="bllb14">全員教育 </div></td>
<td width="7" height="32"></td>
<td ex="true" width="94" height="32" align="right" valign="middle" background="../images/an_02.jpg" style="cursor:pointer"
onClick="tabPanelEx(this,'../images/an_02.jpg','../images/an_01.jpg','newTabs','newsTab2')" >
<div style="width:72px;height:28px;line-height:28px;text-align:left;" class="bllb14">醫界動態 </div></td>
</tr>
</table>
</td>
</tr>
<!-- 間隙 -->
<tr>
<td height="5" align="center"></td>
</tr>
<!-- 對應內容 -->
<tr>
<td align="center">
<div id="newTabs">
<div id="newsTab1">
<table width="768" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="384" height="240" align="left" valign="top"><p>全員教育</p>
</td>
<td width="1" height="240" background="../images/a_07.jpg"></td>
<td width="384" height="240" align="right" valign="top">全員教育</td>
</tr>
</table>
</div>
<div id="newsTab2" style="display:none">
<table width="768" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="384" height="240" align="left" valign="top">醫界動態</td>
<td width="1" height="240" background="../images/a_07.jpg"></td>
<td width="384" height="240" align="right" valign="top">醫界動態</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
調用解釋:
(1)使用的為table,table結構為:
代碼
復制代碼 代碼如下:
<table width="768" border="0" cellspacing="0" cellpadding="0">
<!-- tab上方按鈕行 -->
<tr valign="bottom">
<td 第一行菜單 tab>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td 調用onClick="tabPanelEx(this,'../images/an_02.jpg','../images/an_01.jpg','newTabs','newsTab1')" 顯示newTabs內的newsTab1>
<div style="width:72px;height:28px;line-height:28px;text-align:left;" class="bllb14">全員教育 </div></td>
<td 調用onClick="tabPanelEx(this,'../images/an_02.jpg','../images/an_01.jpg','newTabs','newsTab2')" 顯示newTabs內的newsTab2>
<div style="width:72px;height:28px;line-height:28px;text-align:left;" class="bllb14">醫界動態 </div></td>
</table>
</td>
</tr>
<!-- 間隙 -->
<tr>
<td height="5" align="center"></td>
</tr>
<!-- 對應內容 -->
<tr>
<td align="center">
<div id="newTabs">
<div id="newsTab1">
全員教育
</div>
<div id="newsTab2" style="display:none">
醫界動態
</div>
</div>
</td>
</tr>
</table>
完整文件下載
JavaScript技術:js tab效果的實現代碼,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。