首页 > 其他 > 详细

闭包写个选项卡

时间:2015-09-08 18:18:39      阅读:214      评论: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; height:30px; line-height:30px; }
input.active { background:yellow; }

#box div { display:none; width:300px; height:300px; background:#ccc; }
#box .active { display:block; }
</style>
<script>
window.onload=function (){
    var aBtn=document.getElementsByTagName(input);
    var oDiv=document.getElementById(box);
    var aDiv=oDiv.getElementsByTagName(div);

    for (var i=0; i<aBtn.length; i++)
    {
        (function (index){
            aBtn[index].onclick=function (){
                for (var i=0; i<aBtn.length; i++)
                {
                    aBtn[i].className=‘‘;
                    aDiv[i].className=‘‘;
                }
                aBtn[index].className=active;
                aDiv[index].className=active;
            };
        })(i);
    }
};
</script>
</head>

<body>
    <input type="button" value="新闻" class="active" />
    <input type="button" value="广播" />
    <input type="button" value="电影" />

    <div id="box">
        <div class="active">1111111111111</div>
        <div>2222222222222</div>
        <div>3333333333333</div>
    </div>
</body>
</html>

 

闭包写个选项卡

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

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