<!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滑动门
------解决方案--------------------
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);
};
};
------解决方案--------------------
Message: Object doesn't support this property or method
报错信息这么明显,对象不支持getElementsByClassName方法,浏览器兼容性问题