js tab效果的實(shí)現(xiàn)代碼
更新時(shí)間:2009年12月26日 02:40:32 作者:
js之類似tab的實(shí)現(xiàn),之前已經(jīng)發(fā)布了很多,需要的朋友多看看。
預(yù)實(shí)現(xiàn)效果:(點(diǎn)擊不同的tab顯示不同面板內(nèi)容)

一:用到的js函數(shù):
復(fù)制代碼 代碼如下:
<script language="javascript" type="text/javascript" >
//變換tab函數(shù)
//原則,外層div里含有內(nèi)層多個(gè)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>
二:頁面調(diào)用代碼;
代碼
復(fù)制代碼 代碼如下:
<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">醫(yī)界動(dòng)態(tài) </div></td>
</tr>
</table>
</td>
</tr>
<!-- 間隙 -->
<tr>
<td height="5" align="center"></td>
</tr>
<!-- 對(duì)應(yīng)內(nèi)容 -->
<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">醫(yī)界動(dòng)態(tài)</td>
<td width="1" height="240" background="../images/a_07.jpg"></td>
<td width="384" height="240" align="right" valign="top">醫(yī)界動(dòng)態(tài)</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
調(diào)用解釋:
(1)使用的為table,table結(jié)構(gòu)為:
代碼
復(fù)制代碼 代碼如下:
<table width="768" border="0" cellspacing="0" cellpadding="0">
<!-- tab上方按鈕行 -->
<tr valign="bottom">
<td 第一行菜單 tab>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td 調(diào)用onClick="tabPanelEx(this,'../images/an_02.jpg','../images/an_01.jpg','newTabs','newsTab1')" 顯示newTabs內(nèi)的newsTab1>
<div style="width:72px;height:28px;line-height:28px;text-align:left;" class="bllb14">全員教育 </div></td>
<td 調(diào)用onClick="tabPanelEx(this,'../images/an_02.jpg','../images/an_01.jpg','newTabs','newsTab2')" 顯示newTabs內(nèi)的newsTab2>
<div style="width:72px;height:28px;line-height:28px;text-align:left;" class="bllb14">醫(yī)界動(dòng)態(tài) </div></td>
</table>
</td>
</tr>
<!-- 間隙 -->
<tr>
<td height="5" align="center"></td>
</tr>
<!-- 對(duì)應(yīng)內(nèi)容 -->
<tr>
<td align="center">
<div id="newTabs">
<div id="newsTab1">
全員教育
</div>
<div id="newsTab2" style="display:none">
醫(yī)界動(dòng)態(tài)
</div>
</div>
</td>
</tr>
</table>
完整文件下載
相關(guān)文章
鼠標(biāo)觸發(fā)移動(dòng)的分層菜單 層菜單moveMenu
會(huì)移動(dòng)的菜單,層菜單,鼠標(biāo)放在菜單上,菜單就會(huì)移動(dòng),上浮的菜單,像是TAB風(fēng)格的菜單,使用了一張圖片,順著代碼可下載到這張修飾的小圖片,需要的朋友可以參考下2012-12-12
msn上的tab功能Firefox對(duì)childNodes處理的一個(gè)BUG
今天公司用到一個(gè)tab功能發(fā)現(xiàn) msn上的不錯(cuò),但是在firefox兼容不好,msn他們的方法就是用了不少的div包含,不過網(wǎng)上有高人解決了。2008-01-01
css 有彈動(dòng)效果的網(wǎng)頁導(dǎo)航
發(fā)了個(gè)韓國(guó)網(wǎng)站(www.firstkids.co.kr)給我,讓我用CSS寫一個(gè)類似這個(gè)網(wǎng)站的導(dǎo)航欄效果。思路是:背景圖像定位!2009-10-10
javascript實(shí)現(xiàn)操作cookie實(shí)現(xiàn)的可記憶菜單
javascript實(shí)現(xiàn)操作cookie實(shí)現(xiàn)的可記憶菜單...2007-07-07
javascript漸變顯示的雅虎中國(guó)選項(xiàng)卡效果代碼
javascript漸變顯示的雅虎中國(guó)選項(xiàng)卡效果代碼...2007-10-10

