源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

浅析javascript 定时器

  • 时间:2021-11-20 20:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:浅析javascript 定时器
setTimeout()--用于指定在一段特定的时间后执行某段程序。           格式: [定时器对象名=]setTimeout(“<表达式>”,毫秒数); 功能: 执行<表达式>一次。 其中表达式是字符串,可以使任意javascript语句
[u]复制代码[/u] 代码如下:
<html> <head> <script type="text/javascript"> //5秒之后执行alert function count(){     setTimeout("alert('执行成功');",5000); } </script> </head> <body> <input type="button" value="执行" onclick="count()"> </body> </html>
setInterval()—重复执行<表达式>,直至窗口、框架被关闭或执行clearInterval 格式: [定时器对象名=]setInterval(“<表达式>”,毫秒) clearInterval() 终止定时器 格式: clearInterval(定时器对象名)
[u]复制代码[/u] 代码如下:
<html> <head> <script type="text/javascript"> var sec=0; var timeId=setInterval("count();",1000); function count(){     document.getElementById("num").innerHTML=sec++; } function stopCount(){     clearInterval(timeId); } </script> </head> <body> <font style="color:red" id="num">0</font>秒钟<input type="button" value="停止" onclick="stopCount();"> </body> </html>
是不是很好用呢,有需要的小伙伴参考下吧。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部