setTimeout 默认是不能 调用带参数的函数的

解决方案 »

  1.   

    如果要这样做, 你在这里搜一下 fason 的帖子
      

  2.   

    你可以用一个页面级全局变量呀!!
    <script>
    var global=null;
    function test(obj)
    {
      if(obj) global = obj; 
      else obj = global;
      setTimeout("test()",1000/2);
    }
    </script>
    <input type=button value="test_obj" name="test_obj" onclick="test(test_obj)">
      

  3.   

    好多内容,在哪里面有呀
    setTimeout 函数只是举个例子
      

  4.   

    多谢,meizz(梅花雪) ,这个办法我也想过,可是如果函数较多比较麻烦有办法时间传递吗
      

  5.   

    可以传递参数,不可以传递对象,你可以传递 test_obj.namefunction test(objname)
    {
    //alert(document.all(objname));
    //test1(document.all(objname)); //ok
    setTimeout("test('"+objname+"')",1000/2);  //error}
    function test1(obj)
    {
    alert(obj);
    }
    </script>
    <input type=button value="test_obj" name="test_obj" onclick="test(test_obj.name)">
      

  6.   

    <script>
    var _st = window.setTimeout;
    window.setTimeout = function(fRef, mDelay) {
    if(typeof fRef == 'function'){
    var argu = Array.prototype.slice.call(arguments,2);
    var f = (function(){ fRef.apply(null, argu); });
    return _st(f, mDelay);
    }
    return _st(fRef,mDelay);
    }function test(x){
    alert(x);
    }
    window.setTimeout(test,1000,'fason');
    </script>这个是阿信的,不过好象没用
      

  7.   

    直接传递的方法有是有, 不过有点麻烦, 你可以对 setTimeout 此类的系统函数进行重载, 让它可以接受更多的参数, 这种例子 fason 写了一个你可以参考参考:var _st = window.setTimeout;
    window.setTimeout = function(fRef, param)
    {
      if(typeof(fRef)== 'function')
      {
        var argu = Array.prototype.slice.call(arguments,2);
        var func = (function(){ fRef.apply(null, argu); });
        return _st(func, param);
      }
      return _st(fRef,mDelay);
    }
    setTimeout("test()", 500, obj);  //这个obj会作为test()函数的参数使用
      

  8.   

    <script>
    function test(obj)
    {
    alert(obj);
    //test1(obj); //ok
    setTimeout("test("+obj.uniqueID+")",1000/2);  //error}
    function test1(obj)
    {
    alert(obj);
    }
    </script>
    <input type=button value="test_obj" name="test_obj" onclick="test(test_obj)">