下面是闭包做选项卡:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>闭包做选项卡</title>
<style type="text/css">
.btns{
width:500px;
height:50px;
}
.btns input{
width:100px;
height:50px;
background-color: #ddd;
color:#666;
border:0;
}
.btns input.cur{
background-color: gold;
} .contents div{
width:500px;
height:300px;
background-color: gold;
display: none;
line-height:300px;
text-align: center;
} .contents div.active{
display: block;
} </style>
<script type="text/javascript"> window.onload = function(){ var aBtn = document.getElementById('btns').getElementsByTagName('input'); var aContent = document.getElementById('contents').getElementsByTagName('div'); //用闭包存起来,这个i就有1,2,3这个值了,不过实际中不这样用,小题大做了
for(var i=0;i<aBtn.length;i++){ (function (i) {
aBtn[i].onclick = function () { for(var j=0;j<aBtn.length;j++){
aBtn[j].className = '';
aContent[j].className = '';
} this.className = 'cur';
aContent[i].className = 'active';
}
})(i)
}
} </script>
</head>
<body>
<div class="btns" id="btns">
<input type="button" value="tab01" class="cur">
<input type="button" value="tab02">
<input type="button" value="tab03">
</div>
<div class="contents" id="contents">
<div class="active">tab文字内容一</div>
<div>tab文字内容二</div>
<div>tab文字内容三</div>
</div> </body>
</html>

jquery库做选项卡:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js库做选项卡</title>
<script type="text/javascript" src="jquery-1.12.4.min.js"></script>
<style type="text/css">
.btns{
width:500px;
height:50px;
}
.btns input{
width:100px;
height:50px;
background-color: #ddd;
color:#666;
border:0;
}
.btns input.cur{
background-color: gold;
} .contents div{
width:500px;
height:300px;
background-color: gold;
display: none;
line-height:300px;
text-align: center;
} .contents div.active{
display: block;
}
</style>
<script type="text/javascript">
$(function () { $('#btns input').click(function(){
//this是原生的对象
$(this).addClass('cur').siblings().removeClass('cur');
//alert($(this).index())弹出索引值
$('#contents div').eq($(this).index()).addClass('active').
          siblings().removeClass('active')
})
})
</script>
</head>
<body>
<div class="btns" id="btns">
<input type="button" value="tab01" class="cur">
<input type="button" value="tab02">
<input type="button" value="tab03">
</div>
<div class="contents" id="contents">
<div class="active">tab文字内容一</div>
<div>tab文字内容二</div>
<div>tab文字内容三</div>
</div>
</body>
</html>

jquery——选项卡的更多相关文章

  1. 实用的Jquery选项卡TAB

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 30个实用的jQuery选项卡/导航教程推荐

    很多网站设计中都使用了选项卡(tabs),在制作选项卡时应用jQuery能够实现很多炫酷的过渡和动画效果.本文为你介绍30个实用的jQuery选项卡教程,希望对你有帮助. 1. Animated Ta ...

  3. click事件和jquery选项卡

    一. click事件 实现效果是点击切换按钮,可以重复的切换背景色 <!DOCTYPE html> <html lang="en"> <head> ...

  4. jQuery选项卡tabulous

    jQuery选项卡tabulous,jQuery,选项卡,tab标签切换代码,扁平设计,jQuery选项卡tabulous是一款支持Scale.Slide.Scale Up.Flip等效果jquery ...

  5. 简单的jquery选项卡效果

    html部分 <ul class="tab"> <li>最新</li> <li class="cur">热门&l ...

  6. jquery选项卡

    用jquery实现选项卡功能 css部分: html部分: 记得一定要引入jquery文件 jquery部分:

  7. jQuery选项卡插件

    html结构 <ul id="tabs" class="tabs"> <li data-tab="users">Us ...

  8. javascript与jQuery选项卡效果

    HTML结构: <!doctype html><html><head><meta charset="utf-8"><title ...

  9. 【特效】jquery选项卡插件,页面多个选项卡统一调用

    把选项卡整合了一下,写成个插件,这样可以整个站,或整个页面有多个选项卡时,统一调用.代码的具体注意事项已经写进注释了.用于js获取元素的class名称必须有,选项卡本身的样式,另再取一个名字来设置(本 ...

随机推荐

  1. poj 2187 Beauty Contest —— 旋转卡壳

    题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  2. Linux不停往外发包

    一台Linux这两天不停往外发包,造成外部无法访问. [root@ct-nat ~]# watch ifconfig-------------查看数据包新增情况 Every 2.0s: ifconfi ...

  3. 编译Python出现Tab,空格的问题

    我们编译python代码时, 经常出现各种因为tab和空格的问题, 例如: IndentationError: unindent does not match any outer indentatio ...

  4. UITextField常见用法

    //实例变量和全局变量的区别 //1.定义位置有区别:全局变量定义在方法的外部,实例变量写在接口文件或者延展中的大括号之内 //2.生命周期:全局变量生命周期和应用程序生命周期相同,实例变量的生命周期 ...

  5. 【转】 Pro Android学习笔记(七五):HTTP服务(9):DownloadManager

    目录(?)[-] 小例子 保存在哪里下载文件信息设置和读取 查看下载状态和取消下载 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件,转载须注明出处:http://blog.csd ...

  6. ES6学习之Class

    一.定义类(ES6的类,完全可以看做是构造函数的另一种写法) class Greet { constructor(x, y) { this.x = x; this.y = y; } sayHello( ...

  7. linux命令-rpm安装和卸载

    软件包 先查看一下rpm包 [root@wangshaojun Packages]# mount /dev/cdrom /mnt/////挂载[root@wangshaojun Packages]# ...

  8. 【问题】Expandable数据集的定义的正确方法,TabActivity弃用替代,Gallery替代,imageswitcher

    Expandable 问题: http://www.cnblogs.com/xingyyy/p/3389611.html 扩展阅读:http://blog.csdn.net/lmj623565791/ ...

  9. ServerSocket01

    ServerSocket表示服务端套接字:我们首先来看下其中的一个构造器: public ServerSocket(int port,int backlog) throws IOException 其 ...

  10. error C2039: “addTextureMesh”: 不是“pcl::visualization::PCLVisualizer”的成员

    error C2039: "addTextureMesh": 不是"pcl::visualization::PCLVisualizer"的成员 PCL 1.6 ...