JS+CSS实现WEB页选项卡式效果

效果:

源码:

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">

<head>

<title></title>

<style type="text/css">

/*公用样式*/

html {background:#fff;font-size:12px;margin:0px;padding:0px;text-align:center;font-family: "Arial", "Helvetica", "sans-serif";}

body {width:500px;margin:10px auto;padding:10px;background:#FFFFFF;}

.tapItems {background:url(http://www.2mysite.net/images/bgTap01.gif) repeat;text-align:left;height:26px;}

.tapItem1 {background:url(http://www.2mysite.net/images/bgTap03.gif) repeat;text-align:center;height:18px; width:81px; padding-top:8px;float:left;}

.tapItem2 {background:url(http://www.2mysite.net/images/bgTap02.gif) repeat;text-align:center;height:18px; width:81px; padding-top:8px;float:left;}

.photocolorblock { background:#D8ECFA;font-size: 1px; height:8px;}

.photobox {border-bottom:#6AB2E4 1px solid;border-left:#6AB2E4 1px solid;border-right:#6AB2E4 1px solid;}

.fontclear { clear: both; font-size: 1px; visibility: hidden; width: 1px; line-height:1px; }

.tapList {text-align:left; padding:6px 20px; width:92%;}

</style>

<base target="_blank" />

<script language="JavaScript">

function MM_reloadPage(init) {  //reloads the window if Nav4 resized

  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; οnresize=MM_reloadPage; }}

  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_showHideLayers() { //v6.0

  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 

    if (v == 'hidden') { obj.display = 'none';} 

    if (v == 'visible') {obj.display = 'block'} }

    obj.visibility=v; }

}

</script>

</head>

<body>

<div class="tapItems">

    <div class="tapItem1" id="Layer2-2">选项卡一</div>

    <div class="tapItem2" id="Layer2-2-1" onClick="MM_showHideLayers('Layer1','','show','Layer2-2','','show','Layer3-3-1','','show','Layer1-1-1','','show','Layer4-4-1','','show','Layer5-5-1','','show','Layer3','','hide','Layer2','','hide','Layer4','','hide','Layer5','','hide','Layer3-3','','hide','Layer1-1','','hide','Layer4-4','','hide','Layer5-5','','hide','Layer2-2-1','','hide')" style="cursor: hand;display:none">选项卡一</div>

    <div class="tapItem2" id="Layer1-1-1" onClick="MM_showHideLayers('Layer2','','show','Layer1-1','','show','Layer3-3-1','','show','Layer2-2-1','','show','Layer4-4-1','','show','Layer5-5-1','','show','Layer3','','hide','Layer1','','hide','Layer4','','hide','Layer5','','hide','Layer3-3','','hide','Layer2-2','','hide','Layer4-4','','hide','Layer5-5','','hide','Layer1-1-1','','hide')" style="cursor: hand">选项卡二</div>

    <div class="tapItem1" id="Layer1-1" style="display:none">选项卡二</div>

    <div class="tapItem2" id="Layer3-3-1" onClick="MM_showHideLayers('Layer3','','show','Layer3-3','','show','Layer1-1-1','','show','Layer2-2-1','','show','Layer4-4-1','','show','Layer5-5-1','','show','Layer1','','hide','Layer2','','hide','Layer4','','hide','Layer5','','hide','Layer1-1','','hide','Layer2-2','','hide','Layer4-4','','hide','Layer5-5','','hide','Layer3-3-1','','hide')" style="cursor: hand">选项卡三</div>

    <div class="tapItem1" id="Layer3-3" style="display:none">选项卡三</div>

    <div class="tapItem2" id="Layer4-4-1" onClick="MM_showHideLayers('Layer4','','show','Layer4-4','','show','Layer1-1-1','','show','Layer2-2-1','','show','Layer3-3-1','','show','Layer5-5-1','','show','Layer1','','hide','Layer2','','hide','Layer3','','hide','Layer5','','hide','Layer1-1','','hide','Layer2-2','','hide','Layer3-3','','hide','Layer5-5','','hide','Layer4-4-1','','hide')" style="cursor: hand">选项卡四</div>

    <div class="tapItem1" id="Layer4-4" style="display:none">选项卡四</div>

</div>

<div class="photobox" id="Layer1">

    <div class="photocolorblock"></div>

    <div class="fontclear"></div>

    <div class="tapList">

        <ul>

            <li><a href="#">选项卡一内容</a></li>

        </ul>

    </div>

    <div class="fontclear"></div>

</div>

<div class="photobox" id="Layer2" style="display:none">

    <div class="photocolorblock"></div>

    <div class="fontclear"></div>

    <div class="tapList">

        <ul>

            <li><a href="#">选项卡二内容</a></li>

        </ul>

    </div>

    <div class="fontclear"></div>

</div>

<div class="photobox" id="Layer3" style="display:none">

    <div class="photocolorblock"></div>

    <div class="fontclear"></div>

    <div class="tapList">

    <ul>

        <li><a href="#">选项卡三内容</a></li>

    </ul>

    </div>

    <div class="fontclear"></div>

</div>

<div class="photobox" id="Layer4" style="display:none">

    <div class="photocolorblock"></div>

    <div class="fontclear"></div>

    <div class="tapList">

    <ul>

        <li><a href="#">选项卡四内容</a></li>

    </ul>

    </div>

    <div class="fontclear"></div>

</div>

<div class="photobox" id="Layer5" style="display:none">

    <div class="photocolorblock"></div>

    <div class="fontclear"></div>

    <div class="tapList">

    <ul>

            <li style="display:NONE"><a href="#">选项卡五内容</a></li>

        </ul>

    </div>

    <div class="fontclear"></div>

</div>

</body>

</html>

实例二:

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>WebTable Sample</title>

  <script language="JavaScript">

            function doClick(index, numTabs, id) {

                document.all(id, index).className = "tab";

                for (var i=1; i < numTabs; i++) {

                    document.all(id, (index + i) % numTabs).className = "backtab";

                }

                document.all(id, index).style.display = "";

                for (var j=1; j < numTabs; j++) {

                  document.all(id, (index + j) % numTabs).style.display = "none";

                }

            }

          </script>

          <style>

            td.code {

              padding-left:10px;

              padding-right:10px;

              padding-top:0px;

              padding-bottom:0px;

              border-left: 1px solid #B1B1B1;

              border-bottom: 1px solid #DADADA;

              border-top: none;

              border-right: 1px solid #DADADA;

            }

            td.tab {

              text-align:center;

              font: verdana;

              width:15%;

              border-top: 1px solid #B1B1B1;

              border-bottom: none;

              border-left: 1px solid #B1B1B1;

              border-left: 1px solid #B1B1B1;

              cursor: hand;

              background: #F0F0F0;

              padding: 3px;

            }

            td.backtab {

              text-align: center;

              font: verdana;

              width: 15%;

              border-top: 1px solid #B1B1B1;

              border-right: none;

              border-bottom: 1px solid #B1B1B1;

              border-left: 1px solid #B1B1B1;

              cursor: hand;

              background: #E3E3E3;

              padding: 3px;

            }

            td.space {

              width:70%;

              font: x-small verdana;

              padding: 0px 0px 0px 0px;

              border-top: none;

              border-right: none;

              border-bottom: 1px solid #B1B1B1;

              border-left: 1px solid #B1B1B1;

              background: white;

            }

          </style>

</head>

<body>

<table cellpadding=0 cellspacing=0 width="100%">

    <tr>

         <td class="tab" id="myTab" οnclick="doClick(0, 2, 'myDiv')">C#</td>

         <td class="backtab" id="myTab" οnclick="doClick(1, 2, 'myDiv')">VB</td>

         <td class="space"> </td>

     </tr>

     <tr>

        <td class="code" colspan="3">

<pre id="myDiv" style="display:">

                    

protected void DataList_EditCommand(object Source, DataListCommandEventArgs e) {

    DataList1.EditItemIndex = (int)e.Item.ItemIndex;

    BindList();

}

</pre>

<pre id="myDiv" style="display:none">

                    

Protected Sub DataList_EditCommand(Source As Object, e As DataListCommandEventArgs)

        DataList1.EditItemIndex = CType(e.Item.ItemIndex, Integer)

        BindList()

End Sub

</pre>

        </td>

    </tr>

</table>

</body>

</html>

效果如下:

实例三

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>新建网页 1</title>

</head>

<style>

<!--

body, form, ul, h1, h2, h3, h4, div, h5, h6, p, a, td, button, select {

    font-family: tahoma, verdana, arial;

    margin: 0;

    padding: 0;

    z-index: 1;

}

body {

    font-size: 8pt;

    color: #777;

    text-align: center;

    background-color:White;

}

#tranTypeTable {

    margin: 4px 0 0;

}

#tranTypeLowerTable TD {

    padding: 4px 4px 4px 0;

}

.tranType {

    padding: 4px 16px 8px;

    border: solid 1px #bbb;

}

.selectedTranType {

    padding: 4px 16px 8px;

    border-top: solid 1px #bbb;

    border-left: solid 1px #bbb;

    border-right: solid 1px #bbb;

    background: #f1f1f1;

}

.tranSpacer {

    border-bottom: solid 1px #bbb;

}

.tranSpacerTd {

    padding: 0 3px;

    border-bottom: solid 1px #bbb;

    background: #fff;

}

.tranTypeBottom {

    height: 20px;

    border-bottom: solid 1px #bbb;

    background: #f1f1f1;

}

.tranTypeBottomLeft {

    height: 20px;

    border-bottom: solid 1px #bbb;

    border-left: solid 1px #bbb;

    background: #f1f1f1;

}

.tranTypeBottomRight {

    height: 20px;

    border-bottom: solid 1px #bbb;

    border-right: solid 1px #bbb;

    padding-right: 4px;

    background: #f1f1f1;

}

//-->

</style>

<script>

function ChangeTransType(transType)

{

    window.location.href = 'url' + transType;

    return false;

}

</script>

<body>

<div>

        <table id="tranTypeTable" cellpadding="0" cellspacing="0" border="0" >

            <tr><td class="tranType" NOWRAP><a href='javascript:ChangeTransType("");'>All Results</a> (6)</td><td class="tranSpacer"> </td><td class="tranType" NOWRAP><a href='javascript:ChangeTransType("For Rent");'>For Rent</a> (4)</td><td class="tranSpacer"> </td><td class="selectedTranType" NOWRAP><a href='javascript:ChangeTransType("For Sale");'>For Sale</a> (1)</td><td class="tranSpacer"> </td><td class="tranType" NOWRAP><a href='javascript:ChangeTransType("Wanted");'>Wanted</a> (1)</td><td class="tranSpacer"> </td><td class='tranSpacer' width='100%' colspan='1'> </td></tr>

        </table>

        <table id="tranTypeLowerTable" cellpadding="0" cellspacing="0">

            <tr><td  width='100%' class='tranTypeBottomLeft' colspan='3'> </td><td nowrap class='tranTypeBottom'><img src='images/icon_map.gif' align='middle' /></td><td nowrap class='tranTypeBottom'><a href='javascript:ToggleMap();'><span id='toggletext'>Map Results</span></a></td><td class='tranTypeBottom'><img src='images/icon_save_search.gif' align='middle' /></td><td nowrap class='tranTypeBottomRight'><a id='saveSearch' href='javascript:ShowSaveSearch(true);'>Add to Saved Searches</a></td></tr>

        </table>

    </div>

</body>

</html>

效果如下:

转载于:https://www.cnblogs.com/jixiaozeng/archive/2012/08/14/2637608.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值