//是否为数组判定
if(Object.prototype.toString.call(value) == '[object Array]') {
//是
}
//是否为对象判定
if(Object.prototype.toString.call(value) == '[object Object]') {
//是
}
//是否为数字判定
if(!isNaN(parseFloat(value)) && isFinite(value)){
//是
}
// 添加或删除数组中的元素 ,会改变原数组
Array.splice(1,2,3)
//1 必需。数组元素的下标,规定从何处添加/删除元素
//2 可选。删除数量
//3 可选。要添加到数组的新元素
// 返回被删除的数组
//数组(字符串)中返回选定的元素 ,不会改变原始数组(字符串)
Array.slice(1,2) //返回选定的元素。
//1 可选。开始截取的下标,负数表示倒数第几个元素
//2 可选。结束截取的下标,
e.preventDefault();//阻止默认行为
e.stopPropagation();//阻止冒泡
//获取随机字符串
function randomString(length) {
let chars = 'abcdefghijklmnopqrstuvwxyz';
let result = '';
for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
//信息存储
function saveValue(key,value) {
value = JSON.stringify(clone(value))
localStorage.setItem(key, value);
}
function getValue(key) {
value = localStorage.getItem(key);
return JSON.parse(value)
}
//清除form表单内容
function clearinput(id) {
$(":input",id)
.not(":button",":reset","hidden","submit")
.val("")
.removeAttr("checked")
.removeAttr("selected");
}
//监听横竖屏切换
window.addEventListener('orientationchange',function () {
window.orientation // 0 横屏 90 竖屏
//xxxxxxxxxx
}, true);
//协议
window.location.protocol
//域名
window.location.host
//路径
window.location.pathname;
//完整地址
window.location.href
//获取单个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);
}
// 获取时间
function formatCurrentDate() {
let now:any = new Date();
let year :any= now.getFullYear(); //得到年份
let month :any= now.getMonth();//得到月份
let date:any = now.getDate();//得到日期
let day :any= now.getDay();//得到周几
let hour :any= now.getHours();//得到小时
let minu :any= now.getMinutes();//得到分钟
let sec :any= now.getSeconds();//得到秒
let MS :any= now.getMilliseconds();//获取毫秒
let week:any;
month = month + 1;
if (month < 10) month = "0" + month;
if (date < 10) date = "0" + date;
if (hour < 10) hour = "0" + hour;
if (minu < 10) minu = "0" + minu;
if (sec < 10) sec = "0" + sec;
if (MS < 100 )MS = "0" + MS;
let arr_week:any = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
week = arr_week[day];
let time:any = "";
// time = year + "年" + month + "月" + date + "日" + " " + hour + ":" + minu + ":" + sec + " " + week;
return year + "-" + month + "-" + date ;
}
//监听页面获取焦点,可用作页面返回验证
next_page = true
window.addEventListener('focus', function() {
if(next_page){
page = 0
loadmore()
}
next_page = false
});