最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

學(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、功能說明

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

<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)代碼說明

/*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代碼說明

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)論

孝感市| 武邑县| 巫溪县| 岳阳市| 玉环县| 香港| 沭阳县| 昌吉市| 高青县| 延川县| 馆陶县| 卢湾区| 喜德县| 马边| 梁山县| 香格里拉县| 琼海市| 额敏县| 黔南| 临桂县| 嘉鱼县| 德格县| 张家界市| 永和县| 平乐县| 阆中市| 新兴县| 平阴县| 河池市| 年辖:市辖区| 万安县| 如东县| 阜平县| 九寨沟县| 治县。| 双城市| 怀柔区| 东兴市| 镇江市| 沙雅县| 禹城市|