zoukankan      html  css  js  c++  java
  • 基础

    重复调用的定时器

    var timer = null;

    if (timer) clearInterval(timer);
    fun();
    timer = setInterval(fun,1000);
    function fun(){

    }
    if (timer) clearInterval(timer);
    
    
    只调用一次的定时器
    setTimeout(function () {

    },5000);
    
    
     

    倒计时
    window.onload = function () {

    var oOldDate = new Date("2016/8/8 23:30:30");
    var oNewDate = new Date("2016/8/9 00:00:00");
    var nChaZhi = oNewDate.getTime()-oOldDate.getTime();
    var chaMiao = 1000;
    var chaFen = chaMiao*60;
    var chaShi = chaFen*60;

    var timer = null;
    if (timer) clearInterval(timer);
    funShowTime();
    timer = setInterval(funShowTime,1000);
    function funShowTime(){
    nChaZhi-=1000;
    var miao = parseInt(nChaZhi%chaFen/chaMiao);
    var fen = parseInt(nChaZhi%chaShi/chaFen);
    var shi = parseInt(nChaZhi/chaShi);
    console.log(shi+""+fen+""+miao+"");
    if (nChaZhi==0){
    if (timer) clearInterval(timer);
    }
    }

    }
     
    短信倒计时
    <div id="box" class="box">
    <input type="text" />
    <button>点击发送短信</button>
    </div>


    * {
    margin: 0;
    padding: 0;
    }
    .box {
    margin: 100px 100px;
    }
     
    window.onload = function () {

    var oBox = document.getElementById("box");
    var oInput = oBox.getElementsByTagName("input")[0];
    var oButton = oBox.getElementsByTagName("button")[0];

    var timer = null;
    oButton.onclick = function() {
    var nChaZhi = 10;

    var that = this;
    if (timer) clearInterval(timer);
    funSendMessage();
    timer = setInterval(funSendMessage,1000);
    function funSendMessage(){
    if (nChaZhi>=0) {
    that.disabled = nChaZhi;
    that.innerHTML = "剩余"+nChaZhi+"";
    if (nChaZhi==0){
    that.innerHTML = "重新发送短信";
    if (timer) clearInterval(timer);
    }
    }
    nChaZhi--;
    }
    }

    }
    
    
     
  • 相关阅读:
    Omi新成员omi-router正式发布
    Omi架构与React Fiber
    Omi框架Store体系的前世今生
    Omi v1.0震撼发布
    omi-cli新版发布-升级webpack2和支持sass生成组件局部CSS
    Omi应用md2site-0.5.0发布-支持动态markdown拉取解析
    Omi应用md2site发布-markdown转网站利器
    AlloyTouch之无限循环select插件
    Omi教程-插件体系
    AlloyTouch之select选择插件
  • 原文地址:https://www.cnblogs.com/WeWeZhang/p/5747755.html
Copyright © 2011-2022 走看看