zoukankan      html  css  js  c++  java
  • js方法笔记

    //获取url参数
    function getQueryString(name) {
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if(r!=null)return  decodeURIComponent(r[2]); return '';
    }
    // 获取文件大小size
    
    function getFileSize(fileSize) {
      let size = Number(fileSize)
      var fileSizeMsg = "";
      if (size < 1024) {
        fileSizeMsg = size.toFixed() + "B"
      }else if (1024 < size && size < 1048576) {
        fileSizeMsg = (size / 1024).toFixed() + "KB"
      } else if (size >= 1048576 && size < 1073741824) {
        fileSizeMsg = (size / 1024 / 1024).toFixed() + "MB"
      } else if (size >= 1073741824) {
        fileSizeMsg = (size / 1024 / 1024 / 1024).toFixed() + "GB";
      }
      return fileSizeMsg;
    }
    // 获取文件类型
    
    function getFileCategory (fileName) {
      var index1 = fileName.lastIndexOf(".");
      var index2 = fileName.length;
      var suffix = fileName.substring(index1+1, index2);//后缀名
      let type = index1 > -1 ? suffix : 'unknown'
      const typeMap = {
        image: ['gif', 'jpg', 'jpeg', 'png'],
        video: ['mp4', 'rmvb', 'avi', 'flv'],
        audio: ['mp3'],
        text: ['txt'],
        pdf: ['pdf'],
        doc: ['doc', 'docx'],
        xls: ['xls', 'xlsx'],
        ppt: ['ppt', 'pptx'],
        zip: ['zip', 'rar']
      }
      Object.keys(typeMap).forEach((_type) => {
        const extensions = typeMap[_type]
        if (extensions.indexOf(type.toLowerCase()) > -1) {
          type = _type
        }
      })
      return type
    }
    //时间格式
    Date.prototype.format = function(format) {
        var date = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S+": this.getMilliseconds()
        };
        if (/(y+)/i.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
        }
        for (var k in date) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1
                    ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
            }
        }
        return format;
    }
  • 相关阅读:
    Codeforces 294B Shaass and Bookshelf:dp
    Codeforces 372B Counting Rectangles is Fun:dp套dp
    Codeforces 402D Upgrading Array:贪心 + 数学
    Codeforces 571B Minimization:dp + 贪心【前后相消】
    Codeforces 509F Progress Monitoring:区间dp【根据遍历顺序求树的方案数】
    codeforces 447E or 446C 线段树 + fib性质或二次剩余性质
    类斐波那契数列的一些性质
    CF 1097D
    最近点对问题
    2018ACM-ICPC EC-Final 现场赛I题 Misunderstanding...Missing 倒着DP
  • 原文地址:https://www.cnblogs.com/wjunwei/p/10340896.html
Copyright © 2011-2022 走看看