看看这个例子:
<script language="javascript">
function hello()
{
       alert("hello!");
}
window.setTimeout(hello,3000);
//-->
</script>
这个例子中程序三秒钟以后弹出:hello
楼主的例子中:window.setTimeout(_hello(userName),3000);程序先走到_hello(userName)这个地方执行了_hello(userName),所以会弹出'_hello calld......',这个函数的返回值是一个函数,三秒以后执行了返回的函数。

解决方案 »

  1.   

    拆开理解....
     <script language="javascript">
    function test(){
    return function(){
    alert('test');
    }
    }//test(); // 没反应var t = test();
    t();  // 弹出 test;// 回到你的代码// test(); 这样是执行函数 test
    // t = test(); // 得到test返回的值  这里test返回的是一个 function(){alert('test')}/*
    你的代码可以这样写 window.setTimeout('_hello(userName)',3000);但里面的 hello(_name) 不会被值行, 因为 _hello(userName) 是返回一个函数,而不是执行一个函数, 返回的这个函数没有被执行 hello(_name) 也就不动作了也就是 setTimeout 3秒钟后会执行 _hello(userName) 而不是执行他返回的函数,不加引号 _hello(userName) 这样这个函数会立即执行, setTimeout执行的是 _hello执行后返回的函数
    */
    </script>
      

  2.   

    setTimeout(function(){alert(_hello(userName))},3000);这么写
      

  3.   

    程序相当于这样
    var f=_hello(userName);这里f得到_hello return的那个function但没有执行
    window.setTimeout(f,3000);这里3秒后执行f,即_hello 返回的function
    f();这样运行一下可以看出是执行了hello(_name);