• 定时器三----js定时器


    方法一:
        
        var t;
        
        //初始化定时器
        $(function(){
            init_fun_timer1();
            
        });
        
        
        function init_fun_timer1(){
            
            //可执行方法
            alert(1);
            
            t = setTimeOut(function(){
                init_fun_timer1()
            }, 1000);
            /*
                还有一种写法: t = setTimOut("init_fun_timer1()",1000); 但不规范。            
             */
        }
        
        #tips:
            注意:这种定时不规范,在不同浏览器的效果可能不同。且该方法是死循环,建议用方法二

    方法二:

    //-----------------------------------------------------------------------
    #示例如下:

        <head>    
            <script type="text/javascript">
                    var timer = window.setInterval("queryExprieCount()",2000);
                    function queryExprieCount(){
                        $.ajax({
                                    type: "POST",
                                    async:true,
                                    cache:false,
                                    url: basePath + 'pc/queryOutTimeCount.do',
                                    dataType : "json",
                                    success:function(data){
                                        if(data != 0){
                                            $("#pcExprieControl").html("");
                                            $("#pcExprieControl").html("存在"+data+"个已过期xx,请及时处理!");
                                            $("#pcExprieControl").show();
                                        }else{
                                            $("pcExprieControl").hide();
                                        }
                                    },
                                    error : function(xhr, status, errMsg) {
                                        com.message("error","监控失败!");                    
                                    }
                                });
                    
                    }
                </script>
        </head>
            
        <body>
            <div id="pcExprieControl" value="" style="color: red;font-size: 20px;">
            </div>
        
        </body>
            
    //----------------------------------------------------------------    
    var timer = window.setInterval("scrollup()", 50);//第一个是方法;第二个是间隔时间,单位ms
    clearInterval(timer);//暂停该定时器

  • 相关阅读:
    微型三维图像传感器采用飞行时间技术
    利用反射计芯片进行非接触式液位测量
    嵌入式传感器是智能移动增长的关键
    传感器融合带来多重好处
    参与机器人技术开发
    管理多供应商物联网项目的10个关键步骤
    基于ARMv8的固件系统体系结构
    嵌入式Linux设备驱动程序:在运行时读取驱动程序状态
    Elasticsearch之配置详解
    Spring Data Elasticsearch 和 x-pack 用户名/密码验证连接
  • 原文地址:https://www.cnblogs.com/nnn123/p/6839187.html
Copyright © 2020-2023  润新知