function tabit(id,cid) {
for(var i=0; i<10; i++){
["tab"+i].className = "taboff";
["ctab"+i].style.display = "none";
}
id.className="tabon";
cid.style.display="block";
}</script>
for(var i=0; i<10; i++){
["tab"+i].className = "taboff";
["ctab"+i].style.display = "none";
}
id.className="tabon";
cid.style.display="block";
}</script>
或者试一下
document.getElementById("tab"+i).class = "taboff";
tab1.className = "taboff";
这样是可以的
<tr id="tab2" style="display:none;" height="200">
因为你的循环是从0到9,包含9的,如果你没有这么多的tr,那肯定执行中就有错了。
你的参数id和cid是怎么传的,
传的是控件本身,还是控件的id要控件本身的话
id.className="tabon";是没有问题的,
要是是控件id的=话,需要改成
document.getElementById(id).className="tabon";
tab1.className = "taboff";
这样是可以的
那一楼的document.getElementById("tab"+i).className = "taboff";应该就正确啊。
你画面上有tab0么
document.getElementById("tab"+i).className = "taboff";
行: 18
字符: 3
代码: 0
URI: http://169.169.120.122:8080/HGHR/hghr_write.asp用如下方法可以通过:
document.getElementById("tab"+i).className = "taboff";
document.getElementById("ctab"+i).style.display = "none";在这儿还是想问一下,上面的写法为什么不对,会有错,怎么改才能对。
只有获取了js对象才可以set它的classname、style等等属性tab1.className = '';//这个相当于java中为对象tab1 提供一个setClassName(String str)方法
<table>
<tr id='tr_1'>....</tr>
<tr id='tr_2'>....</tr>
<tr id='tr_3'>....</tr>
...........
</table> for(var i = 0 ; i < 10 ; i ++){
try{
document.getElementById("tr_" + i).className = "newClassName";
}catch(e){
//TODO
}
}