• js延迟执行函数


    在js中,延迟执行函数有两种:setTimeout和setInterval

    setTimeout("test()","2000");  //2000毫秒后执行test()函数,只执行一次。
    setInterval("test()","2000"); //每隔2000毫秒执行一次test()函数,执行无数次。
    var interval = window.setInterval("test()","2000");
    window.clearInterval(interval);     //停止执行setInterval循环。
    
    当我们想让test()函数每隔2000毫秒执行一次,执行10000毫秒后停止执行时,可以用两者三者结合使用来实现。
    var interval2 = window.setInterval("openit2()",2000);
    setTimeout(function() {window.clearInterval(interval2);},10000);
    
    带参方法执行延迟
    setTimeout(function(){return executeQueryTask(data);},"10000");

    例子:

    <html>
      <head>    
        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <script>
            var num = 3;
            window.onload = function(){
                var s = window.setInterval(function(){
                    document.getElementById("s").innerHTML=num;
                    num--;
                    if(num<=0){
                        window.close();
    
                    }
                }, 1000);            
            }
        </script>
        
      </head>
      <body>
            <h1><s:property value="msg"/></h1>
            <h2>本窗口在<span id="s">3</span>秒之后关闭!</h2>
            <input type=button value=关闭窗口  onclick="window.close();"  />
      </body>
    </html>

    angularJs 的延迟是 $timeout方法

    //当timeout被定义时,它返回一个promise对象
                        var timer = $timeout(
                            function() {
                                console.log( "Timeout executed", Date.now() );
                            },
                            2000
                        );
  • 相关阅读:
    ORACLE 11g RACRAC DG Duplicate 搭建(生产操作文档)
    oracle跨数据库
    Linux查看网络流量
    数据库性能监控脚本
    三节点DG环境主库单机转RAC(DG主备切换)
    Oracle dblink介绍
    script 加载失败触发onerror事件
    流程图
    The State of JavaScript 2019
    throw , console.error, new Error
  • 原文地址:https://www.cnblogs.com/miny-simp/p/7120394.html
Copyright © 2020-2023  润新知