美文网首页
延迟选项卡

延迟选项卡

作者: 编程师小刘 | 来源:发表于2016-12-02 14:38 被阅读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>
    

    相关文章

      网友评论

          本文标题:延迟选项卡

          本文链接:https://www.haomeiwen.com/subject/zfqqmttx.html