JS Timer Method SetInterval (), SetTimeout ()

Source: Internet
Author: User

Window.setinterval () periodically invokes a function or executes a piece of code.

1 var intervalid = window.setinterval (func, delay[, param1, param2, ...]); 2  var intervalid = window.setinterval (code, delay); Not recommended

Window.clearinterval () cancels setInterval the recurring action with the set .

1 window.clearinterval (intervalid)

Instance:

1<script type= "Text/javascript" >2$ (document). Ready (function(){3         //Method One4         varNINTERVID1 = SetInterval (Flashtext, 2000);5         //Method A6         varNINTERVID2 = SetInterval ("Flashtext ()", 2000);7         //Not recommended8         varNINTERVID3 = SetInterval ("Console.log (' Hello world! ')", 3000);9         // Ten         varNIntervId4 = SetInterval (function(){ OneConsole.log ("Hello boyy!"); A},3000); -         //Clear - clearinterval (NINTERVID1); the     }); -     // -     functionFlashtext () { -Console.log ("Exec function Flashtext ()"); +     } -</script>

Window.settimeout call a function or execute a code fragment after the specified delay time .

var timeoutid = window.settimeout (func, delay, [param1, Param2, ...]);  var timeoutid = window.settimeout (code, delay); Not recommended

window.clearTimeout() 取消掉用setTimeout设置的重复执行动作。

1  Window.clearinterval (Timeoutid)

JS Timer Method SetInterval (), SetTimeout ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.