<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
.div1 {width:400px; height:300px; background:#CCC; border:1px solid #999;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function ()
{
var aBtn=document.getElementsByTagName('input');
var oDiv=document.getElementsByClassName('div1'); var i;
for(i=0;i<aBtn.length;i++)
{
aBtn[i].index = i;
aBtn[i].onclick=function ()
{
oDiv[i].style.display='block';
};
};
};
</script>
</head>
<body>
<input type="button" value="按钮1" />
<input type="button" value="按钮2" />
<input type="button" value="按钮3" />
<div class="div1">11111
</div>
<div class="div1" style="display:none;">22222
</div>
<div class="div1" style="display:none;">33333
</div>
</body>
</html>
javascript  tab滑动门

解决方案 »

  1.   


    window.onload=function ()
    {
    var aBtn=document.getElementsByTagName('input');
    var oDiv=document.getElementsByClassName('div1');
    var i;
    for(i=0;i<aBtn.length;i++)
    {
    aBtn[i].index = i;
            //下面要注意
    aBtn[i].onclick=(function(_i){
    return function (){
    oDiv[_i].style.display='block';
    }
    })(i);
    };
    };
      

  2.   

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    改成
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    试试编码问题
      

  3.   

    还是不行啊,ie提示var oDiv=document.getElementsByClassName('div1'); 
    Webpage error detailMessage: Object doesn't support this property or method
    错误
      

  4.   

    IE不支持getElementsByClassName,你用firefox或者google
      

  5.   

    Message: Object doesn't support this property or method报错信息这么明显,对象不支持getElementsByClassName方法,浏览器兼容性问题
      

  6.   

    IE就是不支持这个方法的,
    LZ可以试试getElementsById(op).className可得到当前对象的css 类
      

  7.   

    这个问题挺搞笑,不支持就是不支持,还为什么?不支持就是没实现这个api。
    另外看了你的代码,就是点击时想隐藏,你给div一个id或者在div中写onclick事件处理也能达到目的。