setInterval('this.show()',this.DelayTime);

解决方案 »

  1.   

    setInterval( 'this.show() ',this.DelayTime);
    这样写的话会显示对象不支持此属性
    如果我写成这样的话
    setInterval( 'show.show() ',this.DelayTime);那声明的时候就必须是
    var show=new showImg();
    必须和setInterval( 'show.show() ',this.DelayTime);中的show.show()相同
    这样写的话那不是起不到自定义类的作用吗,没有实际意义,
    而且var show=new showImg();还必须定义为全局的期待楼下
      

  2.   

    在无名函数 Show中 设置一个返回值  要不然 你调用了也没说明效果;;
    function test(){
       this.f1="";
       this.DelayTime=1000;
    }
    test.prototype.show=function(){
            this.f1 = "fdsafsda";
            return this.f1;};
    test.prototype.play = function(){
        alert(this.show());
    };这样你就能看出来了  是调用了 Show函数
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>
    <script type="text/javascript">
    function test(){
       this.str="test";
       this.DelayTime=1000;
    }
    test.prototype.show=function(){
            alert(this.str);};
    test.prototype.play = function(){
        setInterval("this.show()",this.DelayTime);
    };
    window.onload=function(){
    var test=new test();
    test.play();
    }
    </script>
    </head>
    <body>
    </body>
    </html>
    大家再看看
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>
    <script type="text/javascript">
    function test(){
       this.str="test";
       this.DelayTime=1000;
    }
    test.prototype.show=function(){
            alert(this.str);
    };
    test.prototype.play = function(){
        setInterval('this.show()',this.DelayTime);
    //setInterval('test.show()',this.DelayTime);
    };
    </script>
    <script type="text/javascript">
    var test=new test();
    test.play();
    </script>
    </head>
    <body>
    </body>
    </html>
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>
    <script type="text/javascript">
    function Test(){
       this.str="test";
       this.DelayTime=1000;
    }
    Test.show=function(str){//改为静态的方法
            alert(str);
    };
    Test.prototype.play = function(){
        //我个人认为可能是因为setInterval是window对象的方法,setInterval要执行的函数必须是window域内的
         //此时this指向的是window,而非Test的实例方法
        setInterval('Test.show("'+this.str+'")',this.DelayTime);//调用静态的方法
    };
    </script>
    <script type="text/javascript">
        var test=new Test();
        test.play();
    </script>
    </head>
    <body>
    </body>
    </html>
      

  6.   

    七楼的代码改了一下:
    setInterval(this.show,this.DelayTime); var a=new Test();
        a.play();
    调试没问题
      

  7.   

    楼上的好象是将this.show()添加到window里了所以window.str="" 运行提示的就为undefind
    看来碰到这样情况只有用静态的,但使用静态的心里感觉太不爽了楼上再看看<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>
    <script type="text/javascript">
    window.str="test2";
    function test(){
       this.str="test";
       this.DelayTime=1000;
    }
    test.prototype.show=function(){
            alert(this.str);
    };
    test.prototype.play = function(){
        setInterval(this.show,this.DelayTime);
    //setInterval('test.show()',this.DelayTime);
    };
    </script>
    <script type="text/javascript">
    var test=new test();
    test.play();
    </script>
    </head>
    <body>
    </body>
    </html>
    感谢大家一起探讨
      

  8.   

    你上面的代码alert出来的是window对象的str吧,而非test实例中的str
    setInterval调用的函数虽然是test实例的方法,但是test.prototype.show=function(){
            alert(this.str);
    };
    中的this==window对象
      

  9.   

    哈哈,那么执着啊
    觉得类静态变量和全局变量不爽,可以在show函数加参数,把this.str传进去
      

  10.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0011)about:blank -->
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=unicode">
    <META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
    <BODY><SCRIPT LANGUAGE="JavaScript">
    <!--
    function test(){
       this.f1="";
       this.DelayTime=1000;
    }
    test.prototype.show=function(){
            this.f1 = "fdsafsda";
    alert(this.f1)
    };
    test.prototype.play = function(){
        setInterval(this.show,this.DelayTime);
    };var t=new test()
    t.play()//-->
    </SCRIPT>
    </BODY></HTML>
      

  11.   

    setInterval("'"+this.show()+"'",this.DelayTime);//评点:相当于setInterval('this.show()的返回值',this.DelayTime)
      

  12.   

    setInterval('this.show()',this.DelayTime);
    //评点:此时的this要放在window领域内的this,因为此处的this是字符串内的this,并不是本对象this