欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

學(xué)習(xí)javascript面向?qū)ο?實(shí)例講解面向?qū)ο筮x項(xiàng)卡

 更新時(shí)間:2016年01月04日 10:14:42   作者:小火柴的藍(lán)色理想  
這篇文章主要介紹了面向?qū)ο筮x項(xiàng)卡實(shí)現(xiàn)方法,幫助大家更好地學(xué)習(xí)javascript面向?qū)ο?,感興趣的小伙伴們可以參考一下

本文實(shí)例講解了最簡(jiǎn)單的面向?qū)ο筮x項(xiàng)卡實(shí)現(xiàn)方法,分享給大家供大家參考,具體內(nèi)容如下

效果圖:

1、功能說(shuō)明

點(diǎn)擊三個(gè)按鈕分別顯示對(duì)應(yīng)的選項(xiàng)卡
2、html代碼說(shuō)明

<div class="box" id="box">
 <ul class="list">
  <li class="in_active">第一張選項(xiàng)卡</li>
  <li class="in">第二張選項(xiàng)卡</li>
  <li class="in">第三張選項(xiàng)卡</li>
 </ul>
 <nav class="conList">
  <a class="con_active" href="javascript:;">第一個(gè)控制按鈕</a>
  <a class="con" href="javascript:;">第二個(gè)控制按鈕</a>
  <a class="con" href="javascript:;">第三個(gè)控制按鈕</a>
 </nav> 
</div>

3、css重點(diǎn)代碼說(shuō)明

/*in為選項(xiàng)卡普通狀態(tài),默認(rèn)不顯示*/
.in,.in_active{
 display: none;
 width: 600px;
 height: 100px;
 background: orange;
 font-size: 50px;
 line-height: 100px;
 text-align: center;
}
/*in_active為選項(xiàng)卡選中狀態(tài),選中后顯示*/
.in_active{
 display: block;
}
/*con為按鈕普通狀態(tài),默認(rèn)文字顏色為黑色*/
.con,.con_active{
 color: black;
 background-color: orange;
}
/*con_active為按鈕選中狀態(tài),選中后文字顏色為白色*/
.con_active{
 color: white; 
}

4、js代碼說(shuō)明

function Tab(obj){
 /*元素獲取*/
 //獲取選項(xiàng)卡展示部分
 this.oList = obj.getElementsByTagName('ul')[0];
 this.aIn = this.oList.getElementsByTagName('li');
 //獲取選項(xiàng)卡控制部分
 this.oConList = obj.getElementsByTagName('nav')[0];
 this.aCon = this.oConList.getElementsByTagName('a');
 /*變量設(shè)置*/
 //選項(xiàng)卡張數(shù)
 this.count = this.aIn.length;
 //當(dāng)前第幾張
 this.cur = 0;
 var _this = this;

 for(var i = 0; i < this.count; i++){
  //設(shè)置索引
  this.aCon[i].index = i;
  //給按鈕添加事件
  this.aCon[i].onclick = function(){
   _this.cur = this.index;
   _this.switch();
  }
 }
}
Tab.prototype.switch = function(){
 //去掉所有
 for(var i = 0; i < this.count; i++){
  this.aIn[i].className = 'in';
  this.aCon[i].className = 'con';
 }
 //顯示當(dāng)前
 this.aIn[this.cur].className = 'in_active';
 this.aCon[this.cur].className = 'con_active'; 
}
//獲取選項(xiàng)卡元素
var oBox = document.getElementById('box');
//構(gòu)造選項(xiàng)卡對(duì)象
var tab1 = new Tab(oBox);

希望本文所述對(duì)大家學(xué)習(xí)javascript面向?qū)ο笥兴鶐椭?/p>

相關(guān)文章

最新評(píng)論