日期:2014-05-16 浏览次数:20364 次
<style> #div1{width:300px; height:30px; background:red; margin:10px;} #div2{width:500px; height:50px; background:blue; margin:10px; display:none;} </style> <script type="text/javascript"> window.onload = function(){ var odiv1 = document.getElementById("div1"); var odiv2 = document.getElementById("div2"); var timer = null; odiv1.onmouseover = odiv2.onmouseover = function(){ odiv2.style.display="block"; clearTimeout(timer); } odiv1.onmouseout = odiv2.onmouseout = function(){ timer = setTimeout(function(){ odiv2.style.display="none"; },300); } } </script> <div id="div1"></div> <div id="div2"></div>
<style type="text/css"> #tab ul{ margin:0; padding:0; list-style:none;} #tab li{ float:left; margin-left:10px; padding:0 5px; background:#FFC; border:#F39 solid 1px;} #tab div{ clear:both; width:500px; height:200px; display:none; border:#FCF solid 1px;} #tab li:hover{ cursor:pointer;} #tab li.selectedLi{background:#9CF; border-bottom:#9CF solid 1px; position:relative; top:1px;} #tab div.selectedDiv{ display:block; background:#9CF} </style> <script type="text/javascript"> function changeTab(nIndex) { var oLis = document.getElementById("tab").getElementsByTagName("li"); var oDivs = document.getElementById("tab").getElementsByTagName("div"); for(var i = 0 ; i < oLis.length; i++) { oLis.item(i).className = ''; oDivs.item(i).className = ''; } oLis.item(nIndex).className = 'selectedLi'; oDivs.item(nIndex).className = 'selectedDiv'; } </script> <div id="tab"> <ul> <li onclick="changeTab(0);" class="selectedLi">新闻频道</li> <li onclick="changeTab(1);">工作频段</li> <li onclick="changeTab(2);">家庭频道</li> <li onclick="changeTab(3);">感情频道</li> <li onclick="changeTab(4);">生活频道</li> </ul> <div class="selectedDiv">选项卡一</div> <div><p>今天不上班啊</p></div> <div><p>明天星期五啊</p><p>上街看北京天文博物馆呀,呵呵</p></div> <div><p>爱一个需要缘分</p><p>快乐的秘诀</p></div> <div><p>释放压力的方法</p><p>晚上睡眠的注意事项</p></div> </div>