zoukankan      html  css  js  c++  java
  • 前端开发 —— js 常用工具函数(utilities)

    1. 时间

    function getCurTime() {
        var date = new Date();
        return date.toLocaleTimeString();
    }
    • date.toLocaleTimeString():上午还是下午,几点几分;
    • date.toLocaleDateString():日期,月和日;

    2. 随机

    • 区间:

      function randInt(low, high) {
          return Math.floor(Math.random()*(high-low) + low)
      }

    3. setInterval 与 setTimeout

    • 每隔 1 秒执行一次:

      setInterval ( function () {
          console.log('hello world')
      }, 1000)
      setInterval ( function () {
          console.log(Math.floor(Math.random()))
      }, 1000)

      如何关闭定时周期执行呢,需要事先保存 id 识别码:

      var id = setInterval ( function () {
          var num = Math.floor(Math.random() * 1024)
          console.log(num)
      }, 3000);
      ....
      clearInterval(id)
    • setTimeout() :定时运行函数,只会在指定时间到时运行一次;

  • 相关阅读:
    第四次作业
    团队编程第三次博客
    团队编程2
    团队编程
    ARM寄存器总结:
    proc介绍及问题分析
    Ubuntu连接手机步骤
    Bluetooth(android 4.2.2版本)
    Android Bluetooth 总结
    android代码常识
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9420987.html
Copyright © 2011-2022 走看看