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>
相关文章
- 从腾讯网提取的判断手机端访问跳转代码
从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w
- JS闪屏代码,闪瞎你的眼睛
JS恶搞代码,页面底色在黑与白之间快速切换,产生闪烁效果。JS闪屏代码,闪瞎你的眼睛。
- JS阻止浏览器返回代码
一段可以阻止浏览器返回的代码,今天无意打开了一个网站,发现怎么也返回不了,仔细研究了一下网站代码找到了无法返回的原因,于是将这段代码提取出来了。 仅供大家学习交流,请勿使用在自己的网站上,这算是一种比较流氓的行为。
- 标题滚动效果演示
纯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
- 假404效果代码
假404效果代码,使用frameset框架覆盖原网页内容,实现网页打不开的假象,直接在网站头部引用404.js即可。 代码下载: 假404效果代码 效果截图:
随机推荐
- 从腾讯网提取的判断手机端访问跳转代码
从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w
- JS闪屏代码,闪瞎你的眼睛
JS恶搞代码,页面底色在黑与白之间快速切换,产生闪烁效果。JS闪屏代码,闪瞎你的眼睛。
- JS阻止浏览器返回代码
一段可以阻止浏览器返回的代码,今天无意打开了一个网站,发现怎么也返回不了,仔细研究了一下网站代码找到了无法返回的原因,于是将这段代码提取出来了。 仅供大家学习交流,请勿使用在自己的网站上,这算是一种比较流氓的行为。
- 标题滚动效果演示
纯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
- 假404效果代码
假404效果代码,使用frameset框架覆盖原网页内容,实现网页打不开的假象,直接在网站头部引用404.js即可。 代码下载: 假404效果代码 效果截图: