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--;
    }
    }

    }
    
    
     
  • 相关阅读:
    footer点击添加active class
    css背景图与html插入img的区别
    js实现游戏转盘抽奖
    gulp压缩css和js
    前后端分离中,gulp实现头尾等公共页面的复用 前言
    js 输入框只能输入 1-7 的数字
    java 环境变量配置
    两日期相减得到天数
    jQuery如何追加tr到table中 添加到头或者尾
    json 添加 和删除两种方法
  • 原文地址:https://www.cnblogs.com/WeWeZhang/p/5747755.html
Copyright © 2011-2022 走看看