JS实现Tab选项卡切换效果的示例代码

2025-09-06

html部分


      <script src="tab.js">  Document  

css部分


*{ padding:0px; margin:0px; list-style: none; font-size: 14px;}#tab{ width:298px; height:120px; margin:10px; border:1px solid #eee; overflow: hidden;}.tab-nav{ width:400px; position:relative; height:27px;}.tab-nav ul{ position:absolute; width:301px; left:-1px; background-color: #f7f7f7;}.tab-nav li{ float:left; width:58px; padding: 0 1px; height:36px; background-color: #f7f7f7; border-bottom: 1px solid #eee; text-align: center;}.tab-nav li.active{ background-color: #fff; border-bottom-color:#fff; border-left: 1px solid #eee; border-right: 1px solid #eee; padding:0px; font-weight: bolder;}li a:link,li a:visited{ text-decoration: none; color:#000;}#tab-contain .mod{ margin:25px 6px 10px 6px;}#tab-contain .mod ul li{ float: left; width:143px; height:25px; overflow: hidden;}

Js部分


function $(id){ return typeof id==='string'?document.getElementById(id):id;}window.onload=function(){ var navs=$('tab-nav').getElementsByTagName('li'); var ps=$('tab-contain').getElementsByTagName('p'); // alert(ps.length); if(navs.length!=ps.length){  return; } for(var i=0;i

标签: 选项卡切换代码

本文地址:http://www.lifejia.cn/news/211486.html

免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。联系邮箱:cloudinto#qq.com(把#换成@)