js 面向对象选项卡

<!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 面向对象选项卡的更多相关文章
- js面向对象选项卡
window.onload=function() //面向对象 { var tab=new tabSwitch("div1"); var tab=new tabSwitch(&qu ...
- 手写js面向对象选项卡插件
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- 原生js面向对象编程-选项卡(点击)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- js面向对象+一般方法的选项卡
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 原生js面向对象编程-选项卡(自动轮播)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 第十五节 JS面向对象实例及高级
实例:面向对象的选项卡 把面向过程的程序,改写成面向对象的形式 原则:不能有函数套函数,但可以有全局变量 过程: onload —— 改写成 构造函数,其中window.onload的功能是在页面加载 ...
- js面向对象、创建对象的工厂模式、构造函数模式、原型链模式
JS面向对象编程(转载) 什么是面向对象编程(OOP)?用对象的思想去写代码,就是面向对象编程. 面向对象编程的特点 抽象:抓住核心问题 封装:只能通过对象来访问方法 继承:从已有对象上继承出新的对象 ...
- ES6学习笔记(三):教你用js面向对象思维来实现 tab栏增删改查功能
前两篇文章主要介绍了类和对象.类的继承,如果想了解更多理论请查阅<ES6学习笔记(一):轻松搞懂面向对象编程.类和对象>.<ES6学习笔记(二):教你玩转类的继承和类的对象>, ...
- JS面向对象介绍
JS面向对象介绍 首先面向对象是什么?为什么要使用面向对象. 因为JavaScript对每个创建的对象都会自动设置一个原型(谷歌火狐中是proto),指向它的原型对象prototype,举个例子: f ...
随机推荐
- android2.2应用开发之IccCard(sim卡或USIM卡)
tyle="margin:20px 0px 0px; font-size:14px; line-height:26px; font-family:Arial; color:rgb(51,51 ...
- Nagios+pnp4nagios+rrdtool 安装配置nagios(一)
基于的软件版本 Apache-2.0.63 php-5.3.2 nagios-3.2.3 nagios-plugins-1.4.15 rrdtool-1.4.5 nrpe-2.12 pnp4na ...
- Reset and clock control (RCC) STM32L
Reset: 1.系统复位:A system reset sets all registers to their reset values except for the RTC, RTC backup ...
- HDU 2828 DLX搜索
Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- 辛星一起了解下后续PHP性能功能
关于第一个发言,这篇文章是我的原创.但,这些数据不被总结出来我,你可以搜索下"百度project师HDK",这些数据提供了他,我只是给一个总结.因为他很长的文章,我在这里提炼几点. ...
- ES6箭头函数和它的作用域
原文来自我的前端博客: http://www.hacke2.cn/arrow-functions-and-their-scope/ http://es6rocks.com/2014/10/arrow- ...
- BackTrack5 (BT5)无线password破解教程WPA/WPA2-PSK无线password皴
昨天公布了BackTrack5 (BT5)无线weppassword破解教程之minidwep-gtk破解法一文,对BT5下破解wep无线password的简单方法做了介绍,今天奶牛为朋友们介绍下怎样 ...
- Quartz CronTrigger运用
CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 同意填写的值 同意的通配符 1 秒 是 0-59 , - ...
- asp.net访问网络路径方法(模拟用户登录)
public class IdentityScope : IDisposable { // obtains user token [DllImport("advapi32.dll" ...
- Phone Number 2010年山东省第一届ACM大学生程序设计竞赛
Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...