延迟选项卡

2016-12-02  本文已影响0人  编程师小刘
<style>

div{

width: 200px;

height: 80px;

border:1px solid #000;

color: red;

display: none;

}

.on{

color: #6cf;

background: green;

}

</style>

<script>

window.onload=function(){

var aBtn=document.getElementsByTagName('input');

var aDiv=document.getElementsByTagName('div');

var timer;

for(var i=0; i<aBtn.length;i++){

aBtn[i].index=i;

aBtn[i].onmouseover=function(){

var _this=this;

timer = setTimeout(function() {

for (var i = 0; i < aBtn.length; i++) {

aBtn[i].className = '';

aDiv[i].style.display = 'none';

}

_this.className = 'on';

aDiv[_this.index].style.display = 'block';

},200);

}

aBtn[i].onmouseout = function(){

clearTimeout(timer);

};

}

}

</script>

</head>

<body>

<input type="button" value="天气" class="on"/>

<input type="button" value="体育" />

<input type="button" value="动漫" />

<div style="display:block;">明天白天多云转晴</div>

<div>今日刘彬代表国家队取得了第一个奖牌</div>

<div>海贼王还要更新10年。。。</div>

</body>
上一篇下一篇

猜你喜欢

热点阅读