有下面代码:
window.setTimeout("tab_switch("+tab_contents+","+show_id+","+show_index+");",delayTime);但是浏览器报错。
FF:缺少]
IE:Object未定义
 
补充一下:
tab_contents为一个数组大家知道怎么回事吗?

解决方案 »

  1.   

    后面的id和index呢?加个‘试试
      

  2.   

    setTimeout("tab_switch("+tab_contents+","+show_id+","+show_index+");",delayTime);setTimeout执行时候,上面的变成setTimeout("tab_switch([x0,..], show_id, show_index);", delayTime);
    tab_contents已经变成了 [xxx],相当于 tab_contents.toString()
    在tab_switch里遍历它的时候应该会出错
      

  3.   

    show_id   和 show_index 例如你show_id ="show_id" ,show_index ="show_index"那么
    setTimeout("tab_switch([x0,..], show_id, show_index);", delayTime);如果你页面没有组件:
    <xxx id="show_id" /> <xxx id="show_index" />这样就会报错show_id,show_index未定义要改成
    setTimeout("tab_switch([x0,..], 'show_id', 'show_index');", delayTime);
      

  4.   

    window.setTimeout("tab_switch(tab_contents,show_id,show_index)",delayTime);
      

  5.   


    FireBug里面好像就是这么说的。那就没有其它办法了吗?
      

  6.   

    你是说show_id和show_index吗?
    它们是参数变量,加上引号就变成字符串了。
      

  7.   

    我这个函数是在其它函数内部执行的,show_id和show_index都是参数,会动态变化的。
      

  8.   

    我也遇到过这问题,目前还没解决,惆怅。settimeout一遇到带参数的函数就很麻烦
      

  9.   

    我这里不行啊!
    火狐下面说tab_contents未定义。
      

  10.   

    window.setTimeout("tab_switch(tab_contents,show_id,show_index)",delayTime);
    改成:
    window.setTimeout(function(){
             tab_switch(tab_contents,show_id,show_index);
    },delayTime);
    试下。
      

  11.   

    window.setTimeout("tab_switch("+tab_contents+","+show_id+","+show_index+");",delayTime);将"tab_switch("+tab_contents+","+show_id+","+show_index+");"部分放在另一函数里
      

  12.   

    我觉得你范了个简单的错误,你试一下
    alert("tab_switch("+tab_contents+","+show_id+","+show_index+");")
    看显示出来的字符串,是可执行的一条语句吗?
      

  13.   


    这个是可以的,谢谢!
    不过我很想知道通过拼接字符串的方式,有没有解决方案?
    因为我以前就是这么处理的。
    今天的这个错误在于
    浏览器将tab_contents解析了,而不是作为参数进行传递。
    火狐报的错误:
    missing ] after element list
    tab_switch([object HTMLCollection],tt,2)
    可以看到其它参数已经成功传递进来了。
      

  14.   

    主要是因为浏览器将tab_contents解析了,而不是作为参数进行传递。
    其它简单数据类型的参数正确传进来了。
      

  15.   

    setTimeout(参数1,参数2);
    了解它的参数含义就好办了,第二个参数没得说,就是时间
    而第一个参数,可以是两种值,第一种是字符串,但这个字符串是可以正常运行的JS代码,也就相当于说,这个字符串是可以被eval正确执行的
    第二种值就是一个函数名,会被直接执行,但无法传递参数。比如第二种的写法就是function run(){
    }setTimeout(run,1);
      

  16.   


    知道了,谢谢!
    测试了一下代码,又发现了浏览器的随机问题:
    window.setTimeout(alert,2000);
    window.setTimeout(alert,3000);
    window.setTimeout(alert,4000);
    上面的代码在FF下面弹出的数字
    会随着你单击确定按钮的时间长短而改变。
    真不知道火狐取的是上面数字。
    IE倒是很规矩,均弹出内容为空。