下面是闭包做选项卡:

<!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. 向vivi中加入命令

    在vivi的lib/command.c中添加自己的命令 核心数据结构user_command. typedef struct user_command { const char *name;      ...

  2. 洛谷【P1885】Moo

    我对分治的理解:https://www.cnblogs.com/AKMer/p/9728574.html 题目传送门:https://www.luogu.org/problemnew/show/P18 ...

  3. Poj 2136 Vertical Histogram(打印垂直直方图)

    一.Description Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text inpu ...

  4. spring 学习 requestMapping

    1:    @RequestMapping:处理请求地址映射的请求,有6个属性? `         value:   URL 地址  method:   GET/POST/PUT/DELETE co ...

  5. BarTender SDK 实现调用模板条码打印

    Demo:MyZebraPrint 基于BatTender .Net SDK 实现调用模板进行条码打印 有需要的朋友可以拿去研究下 在已经安装了BatTender10.1的电脑里测试通过. 下载地址: ...

  6. SpringMvc之参数绑定注解详解之二

    2 consumes.produces 示例 cousumes的样例: 1 @Controller   2 @RequestMapping(value = "/pets", met ...

  7. 关于JAVA中的回调接口传值机制

    详见博文http://blog.csdn.net/xiaanming/article/details/8703708

  8. C++类和对象的一个简单的实例

    题目:找出一个整形数组中的元素的最大值 下面,我们用类和对象的方法来做. #include<iostream> using namespace std; class Array_max{ ...

  9. Git for Windows,TortoiseGit支持WinXP的最后版本及下载方法

    TortoiseGit兼容Windows XP和Windows Server 2003的最后版本: TortoiseGit 1.8.16.0 (https://download.tortoisegit ...

  10. 介绍一款“对话框”组件之 “artDialog”在项目中的使用

    在实际开发项目中经常会用到对话框组件,提示一些信息.其实有很多,例如:在项目中常用到的“Jquery-UI.Jquery-EasyUI”的.Dialog,他们也很强大,Api文档也很多.今天就介绍一款 ...