记录前端工作中用的一些常用的函数
// 判断终端 function getTerminal() { var ua = navigator.userAgent.toLowerCase(); if (/iphone|ipad|ipod/.test(ua)) { return "ios"; } else if (/android/.test(ua)) { return "android"; } else { return "PC"; } }
// 判断是否是微信 function isWeiXin() { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }
//获得地址栏参数 function getQueryString(name) { var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i")); if (result == null || result.length < 1) { return ""; } return result[1]; }
formatDate(weekNum){ let now=new Date(); let todayNowTime=now.getTime()% 86400000; let todayNowWeekNum=now.getDay(); if(todayNowWeekNum==0){ todayNowWeekNum=7; } let nowWeekMondaySec=(now-todayNowTime-(todayNowWeekNum-1)*86400000)/1000-3600*8; nowWeekMondaySec+=86400*weekNum*7; let nowWeekMonday=timeHandler.getLocalDateTime(nowWeekMondaySec,"-",10); let showWeekLitsClone=[]; let showWeekStrLits=["周一","周二","周三","周四","周五","周六","周日"]; for(let i=0;i<7;i++){ showWeekLitsClone.push({ dateStr:timeHandler.getLocalDateTime(nowWeekMondaySec+i*86400,"-",10), weekStr:showWeekStrLits[i], dateStrSec:nowWeekMondaySec+i*86400 }) } this.showWeekLits=showWeekLitsClone; },
}