setTimeout和setInterval的区别

来源:互联网 发布:软件测试时间安排 编辑:程序博客网 时间:2024/06/05 15:53

<html>  <body bgcolor=lightcyan text=red>  <h1> <font color=blue> 示范网页 </font> </h1> <p> </br>  <p> 请等三秒!  <script>  setTimeout("alert(‘对不起, 要你久候’)", 3000 )  </script>  </body>  </html>  


function click() {// code block1...setTimeout(function() {// process ...}, 200);// code block2} 

setTimeout("alert('对不起, 要你久候')",3000 )

setTimeout('clearWord()',3000)


 function click() { // code block1... setInterval(function() { // process ... }, 200); // code block2 } 


<html><head><script type="text/javascript">var c=0var tfunction timedCount(){document.getElementById('txt').value=cc=c+1t=setTimeout("timedCount()",1000)}function stopCount(){clearTimeout(t)}</script></head><body><form><input type="button" value="开始计时!" onClick="timedCount()"><input type="text" id="txt"><input type="button" value="停止计时!" onClick="stopCount()"></form><p>请点击上面的“开始计时”按钮。输入框会从 0 开始一直进行计时。点击“停止计时”可停止计时。</p></body></html>


0 0
原创粉丝点击