• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ninali
此时需要的是坚持~坚持
博客园    首页    新随笔    联系   管理    订阅  订阅
js面向对象选项卡
window.onload=function() //面向对象
{
    var tab=new tabSwitch("div1");
    var tab=new tabSwitch("div2");
};

function tabSwitch(id) 
{    
var obox=document.getElementById("id");
this.abtn=document.getElementsByTagName('input');
this.odiv=document.getElementsByTagName('div'); 

for(var i=0;i<this.abtn.length;i++)
    {
        var _this=this;
        this.abtn[i].index=i;
        this.abtn[i].onclick=function()
        {
            _this.Otab(this);
        };
    };
};    
    
tabSwitch.prototype.Otab=function (Obtn)
{
    
    for(var i=0;i<this.abtn.length;i++)
    {
        this.odiv[i].style.display="none";
        this.abtn[i].className="";
    }
    this.odiv[Obtn.index].style.display="block";
    Obtn.className="active";
    
};


</script>
<script type="text/javascript">  //面向过程
window.onload=function()
{
    var oinput=document.getElementsByTagName("input");
    var odiv=document.getElementsByTagName("div");    
    for(var i=0;i<oinput.length;i++)
    {
        oinput[i].index=i;
        oinput[i].onclick=function()
        {
            for(var i=0;i<oinput.length;i++)
            {
                odiv[i].style.display="none";
                oinput[i].className="";
            };
            odiv[this.index].style.display="block";
            this.className="active";
        };
    };
};
</script>

 

<span id="div1" style="display:block;width:500px; background-color:none;">  
    <input type="button" value="first" class="active" ID="in"/>
    <input type="button" value="two" ID="in"/>
    <input type="button" value="three" ID="in"/>
    <input type="button" value="four"  ID="in"/>
    <input type="button" value="five" ID="in"/>
    <input type="button" value="sixth" ID="in"/>
    <div style="display:block;">1111</div>
    <div >22</div>
    <div >33</div>
    <div >44</div>
    <div >55</div>
    <div >第六个显示区域</div>
</span>

 

 

posted on 2013-07-25 15:43  ninali  阅读(314)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3