博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
收藏一些常用的methods
阅读量:5290 次
发布时间:2019-06-14

本文共 3978 字,大约阅读时间需要 13 分钟。

 

获取url 参数值 getQueryString: function (name) {  let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  let r = window.location.search.substr(1).match(reg);  if (r != null) return unescape(r[2]);    return null;},
 
深度拷贝  copyDeep: function (obj) {    let copy;    if (typeof obj === 'object') {      copy = aa(obj);    }    function aa(oo) {      try {        let c;        if (!isNaN(oo.length)) {          c = [];          for (let i in oo) {            let o = oo[i];            if (typeof o === 'object') c.push(aa(o));            else c.push(o);          }        } else {          c = {};          for (let i in oo) {            c[i] = oo[i];          }        }        return c;      } catch (e) {        return null;      }    }    return copy;  },
全局提示框  myTips: function myTips(type, data) {    let fullDom = approach.fullscreenElement();    if (!document.getElementById('warning')) {      if(!fullDom) {         $('body').append('
'); } else if(fullDom && fullDom.id === 'vsAgainst') { $('#vsAgainst').append('
'); } } let tip = ""; switch (type) { case "success": tip = $("

" + data + "

"); break; case "warning": tip = $("

" + data + "

"); break; } $("#warning").append(tip); setTimeout(function () { tip.remove(); }, 4000); },
分页查询 pageSet: function (wholePage, page) {    if (wholePage == 1) {      return "";    } else if (wholePage <= 9) {      var pages = "";      for (var i = 1; i <= wholePage; i++) {        if (i == page) {          pages += "" + i + "";        } else {          pages += "" + i + "";        }      }      return "" + pages + "";    } else {      var pages1 = "",        pages2 = "";      if (page <= 3) {        for (var i = 1; i < 5; i++) {          if (i == page) {            pages1 += "" + i + "";          } else {            pages1 += "" + i + "";          }        }        for (var i = wholePage - 3; i <= wholePage; i++) {          pages2 += "" + i + "";        }        return "" + pages1 + "..." + pages2 + ""      } else if (page > 3 && page < wholePage - 5) {        for (var i = page - 1; i <= page + 1; i++) {          if (i == page) {            pages1 += "" + i + "";          } else {            pages1 += "" + i + "";          }        }        for (var i = wholePage - 2; i <= wholePage; i++) {          pages2 += "" + i + "";        }        return "1..." + pages1 + "..." + pages2 + ""      } else {        for (var i = wholePage - 6; i <= wholePage; i++) {          if (i == page) {            pages2 += "" + i + "";          } else {            pages2 += "" + i + "";          }        }        return "1..." + pages2 + ""      }    }  },
//判断空对象  isEmptyObject: function (e) {    let t;    for (t in e)      return !1;    return !0  },

 

//url转为base64编码      convertImgToBase64: function (url, callback, outputFormat) {        url+='?random='+Math.random();        let canvas = document.createElement("CANVAS"),          ctx = canvas.getContext("2d"),          img = new Image();        img.crossOrigin = "";        // img.setAttribute("crossOrigin", "anonymous");        img.onload = function () {          canvas.height = img.height;          canvas.width = img.width;          ctx.drawImage(img, 0, 0);          var dataURL = canvas.toDataURL(outputFormat || "image/png");          callback.call(this, dataURL);          canvas = null;        };        img.src = url;      },

  

//将base64编码转换为Blob      convertBase64UrlToBlob: function (urlData) {        let bytes = window.atob(urlData.split(",")[1]); //去掉url的头,并转换为byte        //处理异常,将ascii码小于0的转换为大于0        let ab = new ArrayBuffer(bytes.length);        let ia = new Uint8Array(ab);        for (let i = 0; i < bytes.length; i++) {          ia[i] = bytes.charCodeAt(i);        }        return new Blob([ab], {type: "image/jpeg", filename: "upload.jpg"});      },

  

转载于:https://www.cnblogs.com/lisiyang/p/8127422.html

你可能感兴趣的文章
在现有的mysql主从基础上,搭建mycat实现数据的读写分离
查看>>
WPF---数据绑定(一)
查看>>
HDU 4903 (模拟+贪心)
查看>>
C++ GC
查看>>
mysql: instr 多个字段 like数据
查看>>
php程序突然不能用file_get_contents()访问远程网址了?
查看>>
git clone 报错 fatal: remote did not send all necessary objects
查看>>
VirtualBox Host-Only 连接设置
查看>>
音频重采样
查看>>
【NOI OJ】一大波题正在飞来(ˉ▽ ̄~) 我才不是 Ctrl C + Ctrl V 的人呢
查看>>
BootStrap学习
查看>>
Unity又称Unity Application Block
查看>>
Git的安装与使用
查看>>
C# AutoResetEvent
查看>>
最近学到的前后端分离知识
查看>>
逆向工具整理
查看>>
应用安全-安全设备-Waf系列-软Waf-云锁
查看>>
安全运维 - Linux系统维护
查看>>
安全运维 - Linux系统攻击应急响应
查看>>
安全运维 - Windows系统维护
查看>>