从一个小例子来看setInterval的使用

从一个小例子来看setInterval的使用


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>乐运动数据同步</title>
    <link href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.css" rel="stylesheet">
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
    <style type="text/css">
    html,body{width:100%;height:100%;margin:0;font:14px "Microsoft Yahei","微软雅黑",Tahoma,Arial,Helvetica,STHeiti;color:#ccc;background-color:#27ae60;}.logo{width:150px;height:64px;background:url(./images/spite_index) -29px -432px no-repeat;margin:80px auto 20px;}.header{color:#f4f4f4;margin-bottom:15px;font-size:21px;font-weight:200;text-align:center;}.header span{font-size:14px;}.form-group{margin-top:40px;margin-bottom:15px;}.form-group .text{width:450px;border:2px solid #27ae60;-webkit-box-shadow:none;box-shadow:none;font-size:16px;padding:13px 30px;border-radius:0;height:auto;text-align:center;margin:10px auto;}.form-group .text:focus{border-color:#208d4e;}a.submit{width:446px;background:#239650;border:1px solid #239650;-webkit-box-shadow:none;box-shadow:none;font-size:18px;color:#fff;padding:10px 30px;border-radius:0;height:auto;text-align:center;margin:0 auto;}a:hover{cursor:pointer;text-decoration:none;background:#208d4e;border-color:#208d4e;}.tip{width:375px;height:87px;background:url(./images/spite_index)-21px -513px;margin:80px auto 0;}
    </style>
    <script type="text/javascript">
    $(function(){

        $('#submit').on('click',function()
        {
        alert("程序已运行!");
        var timeTask=setInterval(function(){
        var date=new Date();
        var h=date.getHours();
        var m=date.getMinutes();
        var s=date.getSeconds();
        if(h==8&&m==59&&s==0){      
        console.log('9点段开始设置');
        runstepset1();                                                             
        }
        if(h==14&&m==59&&s==0){
        runstepset2(); 
        console.log('15点段开始设置');

        }
        if(h==21&&m==15&&s==28){
        runstepset3(); 
        console.log('21点段开始设置');                                                          
        }
    },1000);

        }       
            )   
        });
    function runstepset1()
    {
        var Min = 0;
        var Max = 8000;
        var Range = Max - Min;   
        var Rand = Math.random();   
        var step = (Min + Math.round(Rand * Range));        
        $.ajax({ //一个Ajax过程
        type : "get",
        dataType: 'JSONP',
        url : 'http://appt.igeekery.com/wx-run/set-step.json?_lan=zh&_k=da3e20cc7e524a5a\
        b22360372f564875&_v=36&_ch=16&_nw=wifi&_sdk=19&_product=fitmix&_terminal=2&uid=458009&uni\
        onid=oIoQTsy2pk-LKb4hnq0EK9m_3QC4&openid=oBmGhuPxQVTPVBfZyWhskgT4TTos&step\='+step, 
        success : function(ret) 
        {
        if(ret.code==0)
        {console.log('设置成功'+step);}
        else
        {console.log('设置成功'+step); }

        },
        error : function(error)
        {console.log('设置失败'+step); }

        });



        }
    function runstepset2()
    {
        var Min = 8000;
        var Max = 16000;
        var Range = Max - Min;   
        var Rand = Math.random();   
        var step = (Min + Math.round(Rand * Range));        
        $.ajax({ //一个Ajax过程
        type : "get",
        dataType: 'JSONP',
        url : 'http://appt.igeekery.com/wx-run/set-step.json?_lan=zh&_k=da3e20cc7e524a5a\
        b22360372f564875&_v=36&_ch=16&_nw=wifi&_sdk=19&_product=fitmix&_terminal=2&uid=458009&uni\
        onid=oIoQTsy2pk-LKb4hnq0EK9m_3QC4&openid=oBmGhuPxQVTPVBfZyWhskgT4TTos&step\='+step, 
        success : function(ret) 
        {
        if(ret.code==0)
        { console.log('设置成功'+step);}
        else
        {console.log('设置成功'+step); }

        },
        error : function(error)
        {console.log('设置失败'+step); }

        });



        }
    function runstepset3()
    {
        var Min = 16000;
        var Max = 24000;
        var Range = Max - Min;   
        var Rand = Math.random();   
        var step = (Min + Math.round(Rand * Range));        
        $.ajax({ //一个Ajax过程
        type : "get",
        dataType: 'JSONP',
        url : 'http://appt.igeekery.com/wx-run/set-step.json?_lan=zh&_k=da3e20cc7e524a5a\
        b22360372f564875&_v=36&_ch=16&_nw=wifi&_sdk=19&_product=fitmix&_terminal=2&uid=458009&uni\
        onid=oIoQTsy2pk-LKb4hnq0EK9m_3QC4&openid=oBmGhuPxQVTPVBfZyWhskgT4TTos&step\='+step, 
        success : function(ret) 
        {
        if(ret.code==0)
        {console.log('设置成功'+step); }
        else
        {console.log('设置成功'+step); }

        },
        error : function(error)
        {console.log('设置失败'+step); }

        });



        }

</script>
</head>
<body>
    <div class="container">
        <div class="logo"></div>
        <p class="header">陆嵩小主,请问是否开始设置的微信运动步数<br/>
            <div class="form-group">
                <form id="form" method="POST" action="http://pl.api.ledongli.cn/xq/io.ashx">
                    <a id="submit" class="form-control submit">确定</a>
                </form>
            </div>

        </p>
        <div class="tip"></div>
    </div>
</body>
</html>

用一个小技巧可以每天固定时刻做一个动作,周而复始,而不是要从现在开始,每隔多少时间做一次。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陆嵩

有打赏才有动力,你懂的。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值