jquery实现的tab切换
1、jQuery能够使用户的html页保持代码和html内容分离,也就是说,不用再在html里面插入一堆js来调用命令了,只需定义id即可。下面跟大家分享一个jquery的tab切换
2、如何使用
调用jquery文件
<script type="text/javascript" src="jquery.js"></script>
jquery实现tab效果
<script>
$(function(){
$("div [id^='tabcc_']").each(
function(i,ob){
$(ob).find('a').bind
('mouseover',function(){
$(ob).find('a').removeClass('on');
$(this).addClass('on');
var cid=$(this).attr('cid');
$(ob).siblings('div').hide();
$(ob).siblings("div[id='courseList_"+cid+"']").show();
});
});
})
</script>
2、关于tab的html结构
<div class="manage">
<div class="manage_title" id="tabcc_0">
<a href="/opencourse/501/index.htm" cid="501" class='on'>战略管理</a>
<a href="/opencourse/502/index.htm" cid="502" >市场营销</a>
<a href="/opencourse/505/index.htm" cid="503" >采购管理</a>
</div>
<div class="manage_txt" id="courseList_501" style="display:block; height:100px; padding:20px;">
789
</div>
<div class="manage_txt" id="courseList_502" style="display:none; height:100px; padding:20px; ">
456
</div>
<div class="manage_txt" id="courseList_503" style="display:none; height:100px; padding:20px; ">
123
</div>
</div>
这个tab切换可以一个页面多个使用,适用于不同结构的tab切换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title></title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script>
$(function(){
$("div [id^='tabcc_']").each(
function(i,ob){
$(ob).find('a').bind
('mouseover',function(){
$(ob).find('a').removeClass('on');
$(this).addClass('on');
var cid=$(this).attr('cid');
$(ob).siblings('div').hide();
$(ob).siblings("div[id='courseList_"+cid+"']").show();
});
});
})
</script>
</head>
<body>
<div class="manage">
<div class="manage_title" id="tabcc_0"> <a href="/opencourse/501/index.htm" cid="501" class='on'>战略管理</a> <a href="/opencourse/502/index.htm" cid="502" >市场营销</a> <a href="/opencourse/505/index.htm" cid="503" >采购管理</a> </div>
<div class="manage_txt" id="courseList_501" style="display:block; height:100px; padding:20px;"> 789 </div>
<div class="manage_txt" id="courseList_502" style="display:none; height:100px; padding:20px; "> 456 </div>
<div class="manage_txt" id="courseList_503" style="display:none; height:100px; padding:20px; "> 123 </div>
</div>
</body>
</html> 相关文章
- 假404效果代码
假404效果代码,使用frameset框架覆盖原网页内容,实现网页打不开的假象,直接在网站头部引用404.js即可。 代码下载: 假404效果代码 效果截图:
- 标题滚动效果演示
纯JS实现的标题滚动效果。代码如下: 复制代码 代码如下: script type=text/javascript (function(){ setInterval(function(){ text = top.document.title; top.document.title=text.substring(1,text.length)+text.substring(0,1); },500); })(); /script
- JS手机端跳转代码
JS手机端跳转代码,通过判断浏览器版本来判断是手机端还是PC端,然后可以做相应的操作。 能够判断IE内核,opera内核,苹果、谷歌内核,火狐内核,是否为移动终端 ,android终端或者uc浏览器,是否为iPhone或者QQHD浏览器,是否iPad,是否web应该程序,没有头
- JS闪屏代码,闪瞎你的眼睛
JS恶搞代码,页面底色在黑与白之间快速切换,产生闪烁效果。JS闪屏代码,闪瞎你的眼睛。
- jquery实现的tab切换
1、jQuery能够使用户的html页保持代码和html内容分离,也就是说,不用再在html里面插入一堆js来调用命令了,只需定义id即可。下面跟大家分享一个jquery的tab切换 2、如何使用 调用jquery文件 script type=text/javascript src=jquery.js/script jquery实现ta
随机推荐
- 假404效果代码
假404效果代码,使用frameset框架覆盖原网页内容,实现网页打不开的假象,直接在网站头部引用404.js即可。 代码下载: 假404效果代码 效果截图:
- 标题滚动效果演示
纯JS实现的标题滚动效果。代码如下: 复制代码 代码如下: script type=text/javascript (function(){ setInterval(function(){ text = top.document.title; top.document.title=text.substring(1,text.length)+text.substring(0,1); },500); })(); /script
- JS手机端跳转代码
JS手机端跳转代码,通过判断浏览器版本来判断是手机端还是PC端,然后可以做相应的操作。 能够判断IE内核,opera内核,苹果、谷歌内核,火狐内核,是否为移动终端 ,android终端或者uc浏览器,是否为iPhone或者QQHD浏览器,是否iPad,是否web应该程序,没有头
- JS闪屏代码,闪瞎你的眼睛
JS恶搞代码,页面底色在黑与白之间快速切换,产生闪烁效果。JS闪屏代码,闪瞎你的眼睛。
- jquery实现的tab切换
1、jQuery能够使用户的html页保持代码和html内容分离,也就是说,不用再在html里面插入一堆js来调用命令了,只需定义id即可。下面跟大家分享一个jquery的tab切换 2、如何使用 调用jquery文件 script type=text/javascript src=jquery.js/script jquery实现ta