• Js倒计时


    一、bom中浏览器打开:

      1、window.open('http://baidu.com') 相当于window.open("http://baidu.com","target")   //指在新窗口打开,不可以后退。

      2、window.open("http://baidu.com","_self")  //指在当前窗口打开,可后退。

      3、location.replace("http://baidu.com")   //指在当前窗口打开,不可后退。

    二、下班倒计时  js
      <h1>下班倒计时:<span id="time"></span></h1>
      <button id="btn" onclick="stopBtn()">停止倒计时</button>
      function cal(){
        //获取当前时间
        var now=new Date();
        //获取目标时间
        var target=new Date(now.toLocaleDateString()+" 19:00:00");    //toLocaleDateString() 指将根据本地时间将date对象部分时间转换成字符串    拼接的空格别忘记

        if(now<=target){
          //毫秒差
          var ms=target-now;

          //将毫秒进行转化,时分秒
          var s=ms/1000;
          var h=parseInt(s/3600);
          h<0&&(h="0"+h);

          var m=parseInt(s%3600/60);

          m<0&&(m="0"+m);
          s=parseInt(s%3600%60);
          s<10&&(s="0"+s);

          //将时间进行拼接
          document.getElementById('time').innerHTML=h+":"+m+":"+s;
        }else{

          document.getElementById("time").innerHTML="00:00:00";

          clearInterval(timer);
          timer=null;

        } 
      }

      var timer=null;
      window.onload=function(){
        cal();
        timer=setInterval(cal,1000); 
      }

      function stopBtn(){

        var btn=document.getElementById("button");
        if(timer){
          clearInterval(timer);

          timer=null;
          btn.innerHTML="启动倒计时";
        }else{

          cal();
          timer=setInterval(cal,1000);
          btn.innerHTML="停止倒计时";
        }
      }

  • 相关阅读:
    关闭NanoPi网卡指示灯(RTL8211E)
    C++有关mutable与const的使用
    全面理解JSX
    Typescript 面向对象 类和接口 属性访问权限 const、readonly和private
    ES6 Iterator迭代器 与 Generator生成器 如何用js封装一个遍历所有可迭代数据结构的方法
    Redux基础必知必会 reducer拆分 中间件 单向数据流
    TypeScript 泛型
    如何实现一个promise
    深入React源码理解ReactElement到底做了什么
    Redux applyMiddleWare 中间件
  • 原文地址:https://www.cnblogs.com/xxp0921/p/5849650.html
Copyright © 2020-2023  润新知