首页 > 其他 > 详细

基础 - 排他思想

时间:2016-08-02 19:11:21      阅读:224      评论:0      收藏:0      [点我收藏+]

技术分享

结构

<div class="box">

    <button>第一</button>
<button>第二</button>
<button>第三</button>
<button>第四</button>
</div>

样式

.special {
font-weight:bold;">#C81623;
}

行为


window.onload = function () {
  function setIndex (aDiv) {
  for(var i= 0,l=aDiv.length;i<l;i++) {
   aDiv[i].index = i;
   }
  }

function clearColor(aDiv) {
for(var i= 0,l=aDiv.length;i<l;i++) {
aDiv[i].className = "";
}
}

var aBox = document.getElementsByClassName("box");
var aButton = aBox[0].getElementsByTagName("button");

  setIndex(aButton);
for(var i= 0,l=aButton.length;i<l;i++) {
aButton[i].onclick = function () {
clearColor(aButton);
this.className = "special";

       console.log(this.index);
}
}
aButton[0].onclick();
}
 

基础 - 排他思想

原文:http://www.cnblogs.com/WeWeZhang/p/5730054.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!