<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
*{ margin:0; padding:0;}
#box{ width:500px; height:400px; margin:20px auto; position:relative;}
#div1,#div2{ position:absolute; top:0; }
#div1 div,#div2 div{ width:200px; height:300px; border:1px #999 solid; display:none; text-align:center; color:#fff;}
#div1 input,#div2 input{ width:62px; height:30px; border:0; color:#fff; background:#333; margin-bottom:2px; }
.active{ background:red !important;}
.bk0{ background:url(../../images/TaylorSwift.jpg) no-repeat center center/contain;}
.bk2{ background:url(../../images/TaylorSwift3.jpg) no-repeat center center/contain;}
.bk3{ background:url(../../images/TaylorSwift4.jpg) no-repeat center center/contain;}
</style>
</head> <body>
<script> window.onload=function(){
var t1=new Tab('div1');
// t1.init(); var t2=new Tab('div2');
// t2.init();
t2.autoplay();
} function Tab(id){
this.oParent = document.getElementById(id);
this.aInput=this.oParent.getElementsByTagName("input");
this.aDiv= this.oParent.getElementsByTagName("div");
this.iNow = 0;
this.init(); // init 可以直接写在这里 new时候自动初始化
} Tab.prototype.init=function(){
var that=this;
for(var i=0;i<this.aInput.length;i++){
this.aInput[i].index=i;
this.aInput[i].onclick=function(){
that.change(this);
};
} }// init end Tab.prototype.change=function(obj){
for(var i=0;i<this.aInput.length;i++){
this.aInput[i].className='';
this.aDiv[i].style.display = 'none';
} obj.className='active';
this.aDiv[obj.index].style.display = 'block';
}//change Tab.prototype.autoplay=function(){
var This = this;
setInterval(function(){
if(This.iNow == This.aInput.length-1){
This.iNow = 0;
}
else{
This.iNow++;
}
for(var i=0;i<This.aInput.length;i++){
This.aInput[i].className = '';
This.aDiv[i].style.display = 'none';
}
This.aInput[This.iNow].className = 'active';
This.aDiv[This.iNow].style.display = 'block';
},3000);
}
</script> <div id="box">
<div id="div1">
<input class="active" type="button" value="1">
<input type="button" value="2">
<input type="button" value="3">
<div style="display:block" class="bk0">11111</div>
<div class="bk3">22222</div>
<div class="bk2">33333</div>
</div> <div id="div2" style="right:0 !important">
<input class="active" type="button" value="1">
<input type="button" value="2">
<input type="button" value="3">
<div style="display:block" class="bk3">第二个的1111</div>
<div class="bk0">第二 222</div>
<div class="bk2">第二个33333</div>
</div> </div> </body>
</html>

js 面向对象选项卡的更多相关文章

  1. js面向对象选项卡

    window.onload=function() //面向对象 { var tab=new tabSwitch("div1"); var tab=new tabSwitch(&qu ...

  2. 手写js面向对象选项卡插件

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  3. 原生js面向对象编程-选项卡(点击)

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. js面向对象+一般方法的选项卡

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

  5. 原生js面向对象编程-选项卡(自动轮播)

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. 第十五节 JS面向对象实例及高级

    实例:面向对象的选项卡 把面向过程的程序,改写成面向对象的形式 原则:不能有函数套函数,但可以有全局变量 过程: onload —— 改写成 构造函数,其中window.onload的功能是在页面加载 ...

  7. js面向对象、创建对象的工厂模式、构造函数模式、原型链模式

    JS面向对象编程(转载) 什么是面向对象编程(OOP)?用对象的思想去写代码,就是面向对象编程. 面向对象编程的特点 抽象:抓住核心问题 封装:只能通过对象来访问方法 继承:从已有对象上继承出新的对象 ...

  8. ES6学习笔记(三):教你用js面向对象思维来实现 tab栏增删改查功能

    前两篇文章主要介绍了类和对象.类的继承,如果想了解更多理论请查阅<ES6学习笔记(一):轻松搞懂面向对象编程.类和对象>.<ES6学习笔记(二):教你玩转类的继承和类的对象>, ...

  9. JS面向对象介绍

    JS面向对象介绍 首先面向对象是什么?为什么要使用面向对象. 因为JavaScript对每个创建的对象都会自动设置一个原型(谷歌火狐中是proto),指向它的原型对象prototype,举个例子: f ...

随机推荐

  1. mini2440裸试验—计算器(LCD显示,触摸屏突破)

    关于Pait_Bmp(x0, y0, x, y, BMPaddr);函数 像素图在屏幕左上角为(0,0),Pait_Bmp中的x0.y0分别像素点初始位置,x,y为BMP图片的X,Y的大小.BMPad ...

  2. The OpenGL pipeline

    1. Vertex Data 2. Vertex Shader 3. Tessellation Control Shader 4.Tessellation evaluation Shader 5. G ...

  3. Android中Dialog的使用

    上一篇博文讲到对话框popWindow的使用,这篇博文主要解说Dialog的使用. 1.什么是Dialog? Dialog就是对话框的一种方式! 在Android开发中.我们常常会须要在Android ...

  4. macbook连接linuxserver后不显示matlab桌面[问题]

    macbook 登录远程linuxserver.Macbook今天,系统版本号10.9.4.这是更新,打开matlab当提醒x11不存在.一个接着安装Xquarz2.7.6. matlab它可以在本地 ...

  5. 怎么做fastreport使用离线数据源

    近期使用做项目发现fastreport使用在线数据源.紧密耦合的数据库连接字符串.在部署稍加注意.easy错误.因此,是否想到脱机使用的数据源. 官方参考: watermark/2/text/aHR0 ...

  6. 0当执行游戏xc000007b错误的解决方法

    如图所示,这个错误是让很多玩家担心. 出现这个错误,可能是硬件的问题,也可能是软件的问题. 可是.因为硬件引起该问题的概率非常小,而且除了更换硬件之外没有更好的解决方法,因此本文将具体介绍怎样通过软件 ...

  7. 深入了解回调函数Java

    打回来.我第一次看到Java编程思想,后来Observer模式也适用于一个回调函数的想法.但是,一直没有重视,在处于劣势的最终面试,越来越明白为什么那么多人说Java编程思想,这本书应该是一遍又一遍, ...

  8. FPGA开机状态

    最近调试FPGA电路时发现一个问题,我从来没有注意过.我们都知道Xilinx的FPGA有三种功率M引脚,这是为了让我们配置三个引脚FPGA装载机模式,什么是主要的字符串.从字符串.并行等.,该手册有. ...

  9. effective c++ 条款5 c++ 默默实现的函数

    当写一个空类c++ 会为我们自动提供四个函数 1 默认构造函数 2 默认析构函数 3 拷贝构造函数 4 默认赋值运算符

  10. Dom操作高级应用

    table tBodies,tHead,tFoot,rows,cells 一个table有多个tbody oTab.tBodies[0].rows[i].style.background = &quo ...