首页 > 其他 > 详细

选项卡

时间:2015-09-09 13:10:00      阅读:230      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com">
<meta name="copyright" content="智能社 - zhinengshe.com">
<title>智能社 - www.zhinengshe.com</title>
<style>
input { width:100px; }
input.active { background:yellow; }

div { display:none; width:320px; height:200px; background:#ccc;  }
div.active { display:block; }
</style>
<script>
window.onload=function (){
    var oNextBtn=document.getElementById(next);
    var oPrevBtn=document.getElementById(prev);
    var aBtn=document.getElementsByTagName(input);
    var aDiv=document.getElementsByTagName(div);
    var timer=null;

    var now=0;

    for (var i=0; i<aBtn.length; i++)
    {
        (function (index){
            aBtn[index].onclick=function (){
                now=index;

                tab();
            };

            aDiv[i].onmouseover=function (){
                clearInterval(timer);
            };

            aDiv[i].onmouseout=function (){
                timer=setInterval(next, 300);
            };

        })(i);
    }

    oNextBtn.onclick=next;

    oPrevBtn.onclick=function (){
        now--;
        if (0>now)
        {
            now=aBtn.length-1;
        }

        tab();
    };

    timer=setInterval(next, 300);

    function next()
    {
        now++;

        if (now==aBtn.length)
        {
            now=0;
        }

        tab();
    }

    function tab()
    {
        for (var i=0; i<aBtn.length; i++)
        {
            aBtn[i].className=‘‘;
            aDiv[i].className=‘‘;
        }

        aBtn[now].className=active;
        aDiv[now].className=active;
    }
};
</script>
</head>

<body>
    <a href="javascript:;" id="prev">上一张</a>
    <input type="button" value="1" class="active" />
    <input type="button" value="2" />
    <input type="button" value="3" />
    <a href="javascript:;" id="next">下一张</a>

    <div class="active">111111</div>
    <div>2222222</div>
    <div>33333333</div>
</body>
</html>

 

选项卡

原文:http://www.cnblogs.com/heboliufengjie/p/4794060.html

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