首页 > 编程 > JavaScript > 正文

js tab 选项卡

2019-11-21 01:23:53
字体:
来源:转载
供稿:网友
一般需要事先写好css样式等
function tab(sId) {
var tabs = document.getElementsByTagName("H2");
var boxs = document.getElementsByTagName("h3");
if ( boxs[sId].style.display=="block"){
boxs[sId].style.display="none";
tabs[sId].style.backgroundColor="#E3F4FE";
tabs[sId].style.color="#000000";
}
else{
boxs[sId].style.display="block";
tabs[sId].style.backgroundColor="#3575CC";
tabs[sId].style.color="#ffffff";
}
for (var i=0; i<tabs.length; i++) {
if ( i != sId) {
boxs[i].style.display = "none";
tabs[i].style.backgroundColor="#E3F4FE";
tabs[i].style.color="#000000";
}
}
}


<h2 onclick="tab();">中英合作自考</h2>
<h3>
<ul>
<li></li>
</ul>
</h3>
</h2>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表