//时间格式化 参数2020-10-20
const shijiantime=(times)=>{
var timearr = times.replace(" ", ":").replace(/\:/g, "-").split("-");
var timestr = timearr[1] + "月" + timearr[2]
return timestr
}
//字符串
shijiantime('2020-10-20') 结果10月20
//时间格式化 参数2020-10-20
Format(times){
var timearr = times.replace(" ", ":").replace(/\:/g, "-").split("-");
var timestr = timearr[1] + "月" + timearr[2] + " "+ timearr[3] +":"+timearr[1]
return timestr
},
Format('2020-10-20 13:20:30') 结果10月20 13:30
//JS获取url参数
function getQueryVariable(variable){
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
//http://www.runoob.com/index.php?id=1&image=awesome.jpg
//调用 getQueryVariable("id") 返回 1
//调用 getQueryVariable("image") 返回 awesome.jpg
/**
* Description:[输出指定n位数的随机数的随机整数]
*
* @param n 指定n位数
*
*/
const RndNum=(n)=>{
var rnd = "";
for (var i = 0; i < n; i++) {
rnd += Math.floor(Math.random() * 10);
}
return rnd;
}
//数组
var timeArr=[];
for(var j = 0; j<res.other.alarmTime.length; j++) {
timeArr.push(shijiantime(res.other.alarmTime[j]))
}
//获取今天/昨天/明天 前N天数据存入数组 用于统计图
const getDateStr=(AddDayCount)=>{
var dd = new Date();
dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
var year = dd.getFullYear();
var mon = dd.getMonth()+1; //获取当前月份的日期
var day = dd.getDate();
return year + '-' + ( mon < 10 ? ( '0' + mon ) : mon ) + '-' + ( day < 10 ? ( '0' + day ) : day) ;
}
/*
今天:getDateStr(0)
昨天:getDateStr(-1)
明天:getDateStr(1)
*/
//d->今日格式化日期
//n->后多少天
const getBeforetime=(d,n)=>{
d = d.replace(/-/g,'/')
d = new Date(d);
var timearray=[]
for (var i=0;i<n ;i++ ){
var dd=d
dd = +dd - 1000*60*60*24*i;
dd = new Date(dd);
var year = dd.getFullYear();
var mon = dd.getMonth()+1;
var day = dd.getDate();
var s = mon+"月"+day;
// var s = year+"-"+(mon<10?('0'+mon):mon)+"-"+(day<10?('0'+day):day);
timearray.push(s)
}
return timearray.reverse();
}
//判断pc与手机
const _isMobile=()=>{
let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
return flag;
}
if (_isMobile()) {
alert('手机')
} else {
alert('pc')
}
function IsPC() {
var userAgentlnfo = navigator.userAgent;
var Agents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var flag = true;
for(var v = 0; v < Agents.length; v++) {
if (userAgentlnfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
//移动端input position: fixed 处理方法
var windheight = $(window).height(); /*未唤起键盘时当前窗口高度*/
$(window).resize(function(){
var docheight = $(window).height(); /*唤起键盘时当前窗口高度*/
if(docheight < windheight){ /*当唤起键盘高度小于未唤起键盘高度时执行*/
$(".cardfoot").css("position","static");
}else{
$(".cardfoot").css("position","fixed");
}
});