js定时器window.setTimeout和setInterval

window.setTimeout(function(){
                            document.getElementById("editorindex").contentWindow.setContent(data.content);

                                //调用iframe里的setContent()方法


                        },800);

setTimeout 和setInterval的功能都是经过某一个时间段后发生某件指定的事件或者方法。

如window.setTimeout(“sleep()”,5000);指的是在5000ms后去执行sleep方法,setTimeout也可以直接写方法体,如window.setTimeout(sleep,5000)

而setInterval不行。

window.setInterval("sleep()",5000)指的是每隔5000ms循环执行sleep()方法。

clearInterval()是用来解除循环的