网上弄了个自动切换选项卡代码,我想上面一段 下面一段 一共12个选项
但是我复制代码后 不能重复用,重复起来就乱套了~~55555 或者有没好点的自动选项卡?先感谢各位了
以下是CSS代码:
<style type="text/css">
body{font-size:9pt;}
/*选项卡*/
.tab{width:400px;border:#ccc 1px solid;margin:0px;}
.tab dl dt{border-bottom:#ccc 1px solid;height:25px;background:#f1f1f1;margin-bottom:-1px;}
.tab dl dt a{float:left;display:block;cursor:pointer;width:60px;height:25px;line-height:25px;text-align:center;background:#f1f1f1;color:#000;}
.tab dl dt a.tabActive{background:#fff;color:#333;font-weight:bold;border-bottom:1px solid #fff;position:relative;border-right:1px solid #ccc;border-left:1px solid #ccc;}
.tab dl dd{padding:10px;height:120px;clear:both;}
</style>这是JS代码:
<script type="text/javascript" src="http://www.zzsky.cn/effect/images/jquery1.3.2.js"></script>
<script type="text/javascript">
//选项卡
$(function(){
$(".tab dl dt>a:first").addClass("tabActive");
$(".tab dl dd ul").not(":first").hide();
$(".tab dl dt>a").unbind("click").bind("click", function(){
$(this).siblings("a").removeClass("tabActive").end().addClass("tabActive");
var index = $(".tab dl dt>a").index( $(this) );
$(".tab dl dd ul").eq(index).siblings(".tab dl dd ul").hide().end().fadeIn("slow");
});
});
</script>
<script type="text/javascript">
//自动轮换选项卡
$(document).ready(function(){
$('.tab dl dt a:first').addClass('tabActive');
$('.tab dl dd ul:first').css('display','block');
autoroll();
hookThumb();
});
var i=-1;//第i+1个tab开始
var offset = 2500;//轮换时间
var timer = null;
function autoroll(){
n = $('.tab dl dt a').length-1;
i++;
if(i > n){
i = 0;
}
slide(i);
timer = window.setTimeout(autoroll, offset);
}
function slide(i){
$('.tab dl dt a').eq(i).addClass('tabActive').siblings().removeClass('tabActive');
$('.tab dl dd ul').eq(i).fadeIn("slow").siblings('.tab dl dd ul').hide();
}
function hookThumb(){
$('.tab dl dt a').hover(
function () {
if (timer) {
clearTimeout(timer);
i = $(this).prevAll().length;
slide(i);
}
},
function () {
timer = window.setTimeout(autoroll, offset);
this.blur();
return false;
}
);
}
</script>这是html代码:<body>
<!--把下面代码加到<body>与</body>之间-->
<div class="tab">
<dl>
<dt><a>菜单一</a><a>菜单二</a><a>菜单三</a><a>菜单四</a><a>菜单五</a><a>菜单六</a></dt>
<dd>
<ul>菜单一内容</ul>
<ul>菜单二内容</ul>
<ul>菜单三内容</ul>
<ul>菜单四内容</ul>
<ul>菜单五内容</ul>
<ul>菜单六内容</ul>
</dd>
</dl>
</div>
</body>
但是我复制代码后 不能重复用,重复起来就乱套了~~55555 或者有没好点的自动选项卡?先感谢各位了
以下是CSS代码:
<style type="text/css">
body{font-size:9pt;}
/*选项卡*/
.tab{width:400px;border:#ccc 1px solid;margin:0px;}
.tab dl dt{border-bottom:#ccc 1px solid;height:25px;background:#f1f1f1;margin-bottom:-1px;}
.tab dl dt a{float:left;display:block;cursor:pointer;width:60px;height:25px;line-height:25px;text-align:center;background:#f1f1f1;color:#000;}
.tab dl dt a.tabActive{background:#fff;color:#333;font-weight:bold;border-bottom:1px solid #fff;position:relative;border-right:1px solid #ccc;border-left:1px solid #ccc;}
.tab dl dd{padding:10px;height:120px;clear:both;}
</style>这是JS代码:
<script type="text/javascript" src="http://www.zzsky.cn/effect/images/jquery1.3.2.js"></script>
<script type="text/javascript">
//选项卡
$(function(){
$(".tab dl dt>a:first").addClass("tabActive");
$(".tab dl dd ul").not(":first").hide();
$(".tab dl dt>a").unbind("click").bind("click", function(){
$(this).siblings("a").removeClass("tabActive").end().addClass("tabActive");
var index = $(".tab dl dt>a").index( $(this) );
$(".tab dl dd ul").eq(index).siblings(".tab dl dd ul").hide().end().fadeIn("slow");
});
});
</script>
<script type="text/javascript">
//自动轮换选项卡
$(document).ready(function(){
$('.tab dl dt a:first').addClass('tabActive');
$('.tab dl dd ul:first').css('display','block');
autoroll();
hookThumb();
});
var i=-1;//第i+1个tab开始
var offset = 2500;//轮换时间
var timer = null;
function autoroll(){
n = $('.tab dl dt a').length-1;
i++;
if(i > n){
i = 0;
}
slide(i);
timer = window.setTimeout(autoroll, offset);
}
function slide(i){
$('.tab dl dt a').eq(i).addClass('tabActive').siblings().removeClass('tabActive');
$('.tab dl dd ul').eq(i).fadeIn("slow").siblings('.tab dl dd ul').hide();
}
function hookThumb(){
$('.tab dl dt a').hover(
function () {
if (timer) {
clearTimeout(timer);
i = $(this).prevAll().length;
slide(i);
}
},
function () {
timer = window.setTimeout(autoroll, offset);
this.blur();
return false;
}
);
}
</script>这是html代码:<body>
<!--把下面代码加到<body>与</body>之间-->
<div class="tab">
<dl>
<dt><a>菜单一</a><a>菜单二</a><a>菜单三</a><a>菜单四</a><a>菜单五</a><a>菜单六</a></dt>
<dd>
<ul>菜单一内容</ul>
<ul>菜单二内容</ul>
<ul>菜单三内容</ul>
<ul>菜单四内容</ul>
<ul>菜单五内容</ul>
<ul>菜单六内容</ul>
</dd>
</dl>
</div>
</body>
代码如下,
html:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JQuery实例-标签页效果</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="css/tab.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/tab.js"></script>
</head>
<body>
<ul id="tabfirst">
<li class="tabin">标签1</li>
<li>标签2</li>
<li>标签3</li>
</ul>
<div class="contentin contentfirst">我是内容1</div>
<div class="contentfirst">我是内容2</div>
<div class="contentfirst">我是内容3</div>
<br />
<br />
<br />
<ul id="tabsecond">
<li class="tabin">装入完整页面</li>
<li>装入部分页面</li>
<li>从远程获取数据</li>
</ul>
<div id="contentsecond">
<img alt="装载中" src="images/img-loading.gif" />
<div id="realcontent"></div>
</div>
</body>
</html>
tab.css:ul,li {
margin: 0;
padding: 0;
list-style: none;
}
#tabfirst li {
float: left;
background-color: #868686;
color: white;
padding: 5px;
margin-right: 2px;
border: 1px solid white;
}
#tabfirst li.tabin {
background-color: #6E6E6E;
border: 1px solid #6E6E6E;
}
div.contentfirst {
clear: left;
background-color: #6E6E6E;
color: white;
width: 300px;
height: 100px;
padding: 10px;
display: none;
}
div.contentin {
display: block;
}#tabsecond li {
float: left;
background-color: white;
color: blue;
padding: 5px;
margin-right: 2px;
cursor: pointer;
}
#tabsecond li.tabin {
background-color: #F2F6FB;
border: 1px solid black;
border-bottom: 0;
z-index: 100;
position: relative;
}
#contentsecond {
width: 500px;
height: 200px;
padding: 10px;
background-color: #F2F6FB;
clear: left;
border: 1px solid black;
position: relative;
top: -1px;
}
img {
display: none;
}
tab.js:var timoutid;
$(document).ready(function(){
//找到所有的标签
/*
$("li").mouseover(function(){
//将原来显示的内容区域进行隐藏
$("div.contentin").hide();
//当前标签所对应的内容区域显示出来
});
*/
$("#tabfirst li").each(function(index){
//每一个包装li的jquery对象都会执行function中的代码
//index是当前执行这个function代码的li对应在所有li组成的数组中的索引值
//有了index的值之后,就可以找到当前标签对应的内容区域
$(this).mouseover(function(){
var liNode = $(this);
timoutid = setTimeout(function(){
//将原来显示的内容区域进行隐藏
$("div.contentin").removeClass("contentin");
//对有tabin的class定义的li清除tabin的class
$("#tabfirst li.tabin").removeClass("tabin");
//当前标签所对应的内容区域显示出来
//$("div").eq(index).addClass("contentin");
$("div.contentfirst:eq(" + index + ")").addClass("contentin");
liNode.addClass("tabin");
},300);
}).mouseout(function(){
clearTimeout(timoutid);
});
});
//在整个页面装入完成后,标签效果2的内容区域需要装入静态的html页面内容
$("#realcontent").load("TabLoad.html");
//找到标签2效果对应的三个标签,注册鼠标点击事件
$("#tabsecond li").each(function(index){
$(this).click(function(){
$("#tabsecond li.tabin").removeClass("tabin");
$(this).addClass("tabin");
if (index == 0) {
//装入静态完成页面
$("#realcontent").load("TabLoad.html");
} else if (index == 1) {
//装入动态部分页面
$("#realcontent").load("TabLoad.jsp h2");
} else if (index == 2) {
//装入远程数据(这里也是一个动态页面输出的数据)
$("#realcontent").load("TabData.jsp")
}
});
});
//对于loading图片绑定ajax请求开始和交互结束的事件
$("#contentsecond img").bind("ajaxStart",function(){
//把div里面的内容清空
$("#realcontent").html("");
//整个页面中任意ajax交互开始前,function中的内容会被执行
$(this).show();
}).bind("ajaxStop",function(){
//整个页面中任意ajax交互结束后,function中的内容会被执行
$(this).slideUp("1000");
});
});自己引入jQuery.js应该能直接运行,少了张加载时的小图片。同时标签页效果jQuery有个插件也不错,使用也简单。
如下:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css"
href="css/easyui.css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="JavaScript" src="js/jquery-1.4.2.min.js"></script>
<script language="JavaScript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" language="JavaScript">
$(function(){
$('#tt').tabs();//就这一句话就实现了标签页效果
//jQuery.js版本也不需要太高
});
</script>
</head>
<body>
<div id="tt">
<div title="BB">BBBBB</div>
<div title="AA">AAAAA</div>
<div title="CC">CCCCC</div>
</div>
</body>
</html>
http://blog.csdn.net/IBM_hoojo/archive/2010/07/28/5772017.aspx