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>
相关文章
- 离线宝中提取的验证电话号码的函数
从百度离线宝中提取的验证电话号码的函数,只检查输入的内容是否是11位或12为数字,不是非常完美,但是代码中还是有值得学习的地方。 函数:phone(e){} 参数:e //要验证的号码 返回值:正确返回true,错误弹出提示框并返回false。 效果图:
- JS判断手机端跳转代码
JS判断手机端跳转代码 复制代码 代码如下: var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf(Trident) -1, //IE内核 Opera: u.indexOf(Opera) -1, //ope
- JS判断手机访问函数
函数is_mobile()手机端返回true,PC端返回false,根据返回值来判断时候是手机端访问,然后做相应的操作。 复制代码 代码如下: script function is_mobile() { var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browse
- Bcastr3.0详细使用教程
Bcastr 3.0 beta flash 通用的图片浏览器 bcastr3.0 beta 是一款通用的图片浏览器 可以用于各种新闻系统或者blog系统 .可以读取xml设置播放列表,自定义xml地址 .可以将图片地址直接写网页中直接,不需要xml .自动适应图片大小 .循环播放,自定义自动播放时间
- 最新获取网站访客QQ接口代码-20141015
分析某网站得到的一枚获取访客QQ的接口,原理和以前的一样jsonp 不废话,直接上代码,不懂的直接百度,这种技术应该早就烂大街了。 详细接口及利用代码: 复制代码 代码如下: script type=text/javascript function getQQ(data){ if(data.uin != 0){ alert(
随机推荐
- 离线宝中提取的验证电话号码的函数
从百度离线宝中提取的验证电话号码的函数,只检查输入的内容是否是11位或12为数字,不是非常完美,但是代码中还是有值得学习的地方。 函数:phone(e){} 参数:e //要验证的号码 返回值:正确返回true,错误弹出提示框并返回false。 效果图:
- JS判断手机端跳转代码
JS判断手机端跳转代码 复制代码 代码如下: var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf(Trident) -1, //IE内核 Opera: u.indexOf(Opera) -1, //ope
- JS判断手机访问函数
函数is_mobile()手机端返回true,PC端返回false,根据返回值来判断时候是手机端访问,然后做相应的操作。 复制代码 代码如下: script function is_mobile() { var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browse
- Bcastr3.0详细使用教程
Bcastr 3.0 beta flash 通用的图片浏览器 bcastr3.0 beta 是一款通用的图片浏览器 可以用于各种新闻系统或者blog系统 .可以读取xml设置播放列表,自定义xml地址 .可以将图片地址直接写网页中直接,不需要xml .自动适应图片大小 .循环播放,自定义自动播放时间
- 最新获取网站访客QQ接口代码-20141015
分析某网站得到的一枚获取访客QQ的接口,原理和以前的一样jsonp 不废话,直接上代码,不懂的直接百度,这种技术应该早就烂大街了。 详细接口及利用代码: 复制代码 代码如下: script type=text/javascript function getQQ(data){ if(data.uin != 0){ alert(