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>

解决方案 »

  1.   

     document.getElementById("tab"+i).className = "taboff";
    或者试一下
     document.getElementById("tab"+i).class = "taboff";
      

  2.   

    如果写成
    tab1.className = "taboff";
    这样是可以的
      

  3.   

    楼主,你["tab"+i]是什么东东?
      

  4.   

    tab1 tab2 tab3 是 行的ID
    <tr id="tab2" style="display:none;" height="200">
      

  5.   

    那你要确定 tab0到tab9,页面上都有吗?
    因为你的循环是从0到9,包含9的,如果你没有这么多的tr,那肯定执行中就有错了。
      

  6.   

    tabit(id,cid)
    你的参数id和cid是怎么传的,
    传的是控件本身,还是控件的id要控件本身的话
    id.className="tabon";是没有问题的,
    要是是控件id的=话,需要改成
    document.getElementById(id).className="tabon";
      

  7.   

    如果写成
    tab1.className = "taboff";
    这样是可以的
      

  8.   


    那一楼的document.getElementById("tab"+i).className = "taboff";应该就正确啊。
      

  9.   

    因为有很多的tab1~tab9,一个一个写很麻烦,我想用一个for将ID变化一下就可以了
      

  10.   

    可你的循环式tab0~tab9
    你画面上有tab0么
      

  11.   

    首先你必须或得对象才能修改其属相 应该这样写
    document.getElementById("tab"+i).className = "taboff";
      

  12.   

    如果这样的写法是对的 ["tab"+i].className = "taboff"; 那么就是tab0的问题了,谢谢大家
      

  13.   

    ["tab"+i].className = "taboff"; ["ctab"+i].style.display = "none";用上述的写法还是不对,我已经考虑了tab0和ctab0的问题了,错误提示如下:消息: 'style' 为空或不是对象
    行: 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";在这儿还是想问一下,上面的写法为什么不对,会有错,怎么改才能对。
      

  14.   

    document.xxxform["tab"+i].className = "taboff";  
      

  15.   


    只有获取了js对象才可以set它的classname、style等等属性tab1.className = '';//这个相当于java中为对象tab1 提供一个setClassName(String str)方法
      

  16.   

    ctab1.style.display = "none";那为什么这样写就可以运行呢
      

  17.   

    ["ctab"+i].style.display = "none";不知道你为何执意要这样写,我觉得像这样应该是可以的:document.getElementById("ctab"+i).style.display = "none";
      

  18.   


     <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
          }
      }
      

  19.   

    如果我没有猜错,楼主想整一个tab切换的功能,但是我就不明白了,为什么大部分人都喜欢使用循环去运算,不觉得这样效率很低的么?
      

  20.   

    参考下我的写法吧,呵呵,http://blog.csdn.net/baolong101010/article/details/7419242