zoukankan      html  css  js  c++  java
  • javascript setTimeout 和 setInterval 区别

    [setTimeout]
    setTimeout(表达式,延时时间)
    在执行时,是在载入后延迟指定时间后,去执行一次表达式,记住,次数 是一次

    用setTimeout实现的自动变化显示随机数的效果:

    <html>
    <head>
    <script>
    window.onload=sett;
    function sett()
    {
    document.body.innerHTML=Math.random();
    setTimeout("sett()",500);
    }
    </script>
    </head>
    <body>
    </body>
    </html>


    [setInterval]
    setInterval(表 达式,交互时间)
    则不一样,它从载入后,每隔指定的时间就执行一次表达式

    用setInterval实现的自动变化显示随机数的效 果:

    <html>
    <head>
    <script>
    function sett()
    {
    document.body.innerHTML=Math.random();
    }
    setInterval("sett();", 500);
    </script>
    </script>
    </head>
    <body>
    </body>

    </html>

    摘自: http://www.cnblogs.com/ruxuan/archive/2006/07/04/442490.html

  • 相关阅读:
    对于 redux 的一些理解-1.基础
    css 优化
    HTML 理解标签
    css 理解盒模型
    json2.js JSON解析程序
    DOM 核心
    居中
    Director.js
    jquery-2.0.3 源码分析 整体架构
    Zookeeper安装
  • 原文地址:https://www.cnblogs.com/haoliansheng/p/1895278.html
Copyright © 2011-2022 走看看