本文實例為大家分享了js選項卡效果的具體實現代碼,供大家參考,具體內容如下
效果圖:
實現代碼:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>無標題文檔</title> <style type="text/css"> body{ font-size:12px;} .sec,.sec1{ cursor:pointer;} .sec{ color:#FFFFFF; font-weight:bold; text-align:center; background-color:#990000;} .sec1{ color:#990000; text-align:center; background-color:#FFFFFF;} div{ line-height:22px;} </style> <script language="javascript"> function $(id){ return document.getElementById(id); } function xxk(num,id,ii,iii) { //alert(ii); var dq; for(var i=1;i<=num;i++) { if(i==id){ dq=$(ii+i).className='sec'; //當前選項 $(iii+i).style.display="block"; } else { dq=$(ii+i).className='sec1'; $(iii+i).style.display="none"; } } } </script> </head> <body> <table width="620" border="0" cellpadding="4" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#990000"> <tr> <td class="sec" id="t1" onmouseover="xxk(5,1,'t','tt')">選項卡1</td> <td bgcolor="#FFFFFF" id="t2" class="sec1" onmouseover="xxk(5,2,'t','tt')">選項卡2</td> <td bgcolor="#FFFFFF" id="t3" class="sec1" onmouseover="xxk(5,3,'t','tt')">選項卡3</td> <td bgcolor="#FFFFFF" id="t4" class="sec1" onmouseover="xxk(5,4,'t','tt')">選項卡4</td> <td bgcolor="#FFFFFF" id="t5" class="sec1" onmouseover="xxk(5,5,'t','tt')">選項卡5</td> </tr> <tr> <td colspan="5" bgcolor="#FFFFFF"> <div id="tt1">選項卡1月在上班</div> <div id="tt2" style="display:none;">選項卡2月在上班</div> <div id="tt3" style="display:none;">選項卡3月在上班</div> <div id="tt4" style="display:none;">選項卡4月在上班</div> <div id="tt5" style="display:none;">選項卡5月在上班</div> </td> </tr> </table> <br /> <table width="620" border="0" cellpadding="4" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#990000"> <tr> <td class="sec" id="ts1" onclick="xxk(4,1,'ts','tts')">選項卡1</td> <td bgcolor="#FFFFFF" id="ts2" class="sec1" onclick="xxk(4,2,'ts','tts')">選項卡2</td> <td bgcolor="#FFFFFF" id="ts3" class="sec1" onclick="xxk(4,3,'ts','tts')">選項卡3</td> <td bgcolor="#FFFFFF" id="ts4" class="sec1" onclick="xxk(4,4,'ts','tts')">選項卡4</td> </tr> <tr> <td colspan="4" bgcolor="#FFFFFF"> <div id="tts1">選項卡1月在上班</div> <div id="tts2" style="display:none;">選項卡2月在上班</div> <div id="tts3" style="display:none;">選項卡3月在上班</div> <div id="tts4" style="display:none;">選項卡4月在上班</div> </td> </tr> </table> </body> </html>
以上就是本文的全部內容,希望對大家的學習有所幫助。