setTimeout or setInterval?

前端 未结 19 3148
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:59

As far as I can tell, these two pieces of javascript behave the same way:

Option A:

function myTimeoutFunction()
{
    doStuff();
           


        
19条回答
  •  粉色の甜心
    2020-11-21 05:36

    You can validate bobince answer by yourself when you run the following javascript or check this JSFiddle

    var timeout = 0; var interval = 0; function doTimeout(){ $('#timeout').html(timeout); timeout++; setTimeout(doTimeout, 1); } function doInterval(){ $('#interval').html(interval); interval++; } $(function(){ doTimeout(); doInterval(); setInterval(doInterval, 1); });

提交回复
热议问题