这段代码的作用是:在元素之间 无限循环切换<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" >
function _init()
{
var obj = document.getElementById('u');
var length = obj.children.length;

var jsq = 0; //记数器
_focus(obj.children,length ,jsq);

}//参数:对象 , 长 , 记数器
function _focus( obj , length , jsq)
{
if( jsq >= length )
{
jsq = 0;
}
obj[jsq].style.color="red";
setTimeout(_blur(obj , length , jsq) , 5000); //setTimeout 这函数有问题 无法等待5秒后去执行我的函数
}function _blur( obj , length , jsq )
{
obj[jsq].style.color="black";
jsq++;
_focus( obj , length , jsq );
}
</script>
<body>
<ul id="u" onClick="_init()">
<li>1:第一</li>
    <li>2:第二</li>
    <li>3:第三</li>
</ul>
</body>
</html>
setTimeout(_blur(obj , length , jsq) , 5000); //setTimeout 这函数有问题 无法等待5秒后去执行我的函数

解决方案 »

  1.   

    setTimeout('_blur(obj , length , jsq)' , 5000);
      

  2.   


    错了啊. 像你这个  我的 obj对象变成 未定义 了
      

  3.   

    setTimeout(
    function(){
       _blur(obj , length , jsq); 
    }, 5000);
      

  4.   

    function _init()
    {
        var obj = document.getElementById('u');
        var length = obj.children.length;
        var jsq = 0; //记数器
        _focus(obj.children,length ,jsq);
    }你_blur(obj , length , jsq)里要用的这些实参,都是_init()里的局部变量,出了_init()就没意义了,当然找不到。应该使用全局变量。另外,你就光这样一直setTimeout那个_blur,又在_blur里_focus,在_focus里再setTimeout,不是找死(死循环)吗?
      

  5.   

    没细看程序。_blur(obj , length , jsq)里的原来是_focus的参数。
    这样的话,比较混乱。局部变量只用到一次,因此没必要声明变量,直接作为参数即可。