setInterval and [removed] problem

后端 未结 4 1850
醉梦人生
醉梦人生 2021-01-22 21:13

I have this code

window.onload = function() {            
    function foo() {
        alert(\"test\");
    }
    setInterval(\"foo()\",500)
}

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 21:49

    Alternatively, you can define the function within the call to setInterval:

    window.onload = function() {
        setInterval(
            function foo() {
                alert("test");
            },
            500
        );
    }
    

提交回复
热议问题