目录
- 原生js获取scrollTop
- 获取字符数
- eval
- Object.prototype.toString.call(data['data'][objName]) === '[object Array]'
- .filter+.map获取有属性A的key数组
- js获取昨日、今日、本周、本月
- Object.assign(A, handle(B),handle(C))
- delete删除属性 delete(this.query['version'])
- A.hasOwnProperty('date')
- 没有更多了 s + this.oScroll.v > y - 100
- navigatorUserAgent
- parseURL
navigatorUserAgent
navigatorUserAgent(isToPC=true){
const ua = navigator.userAgent,
isWindowsPhone = /(?:Windows Phone)/.test(ua),
isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
isAndroid = /(?:Android)/.test(ua),
isFireFox = /(?:Firefox)/.test(ua),
isChrome = /(?:Chrome|CriOS)/.test(ua),
isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)),
isPhone = /(?:iPhone)/.test(ua) && !isTablet,
isPc = !isPhone && !isAndroid && !isSymbian;
console.log(ua)
if(isToPC && isPc){
window.location.href = 'https://www.XXXXX.com' +'/'+ window.location.href.split('m.XXXXX.com/')[1];
return {}
} else {
const oUa = {ua, isPc: isPc,}
const isVx = window.__wxjs_environment === 'miniprogram'
return Object.assign(oUa, {
isVx: isVx,
isVxBrowser: !isVx && ua.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'
})
}
},
parseURL
function parseURL(url) {
const a = document.createElement('a')
a.href = url
let ret = {}, seg = a.search.replace(/^\?/, '').split('&')
for (let i = 0; i < seg.length; i++) {
if (!seg[i]) {
continue
}
const s = seg[i].split('=')
ret[s[0]] = s[1]
}
return ret
}
没有更多了
scrollBottom() {
if (!this.oList.next || this.oList.loading) {
return false
}
const s = document.documentElement.scrollTop || document.body.scrollTop
const y = document.getElementById('_newsList').offsetHeight
if (s + this.oScroll.v > y - 100) {
this.$tools._debounce(this.getList, 500)
}
},
.loadMore{
.px(padding-bottom, 248);border:0 none;
.px(font-size, @F24);text-align:center;
color:@HC8C8C8;
}
scrollTop
const y = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
注意: overflow:auto
[学习来源_原生js获取scrollTop](https:
获取字符数
_getCharLen(str) {
let len = 0
for (let i = 0; i < str.length; i++) {
str.charCodeAt(i) > 127 || str.charCodeAt(i) == 94 ? len += 2 : len++
}
return len
},
eval
try { eval(`data.${fieldNames eg:'data.data.data' }`) } catch (e) { }
[object Array]
Object.prototype.toString.call(data['data'][objName]) === '[object Array]'
.filter+.map获取有属性A的key数组
this.arrSortkey = this.array
.filter(el => el.hasOwnProperty('sortable'))
.map(el => el.sortkey)
$dateFormat日期转换
const $dateFormat={
Dateformat(oTime, format='yyyy-MM-dd') {
let time = oTime.date
? new Date(!(/^[1-9]\d*$/.test(oTime.date)) ? `${oTime.date}`.replace(/-/g, '/') : oTime.date)
: new Date()
oTime.day && time.setTime(time.getTime() + 3600 * 1000 * 24 * oTime.day)
const date = {
'M+': time.getMonth() + 1,
'd+': time.getDate(),
'h+': time.getHours(),
'm+': time.getMinutes(),
's+': time.getSeconds(),
'q+': Math.floor((time.getMonth() + 3) / 3),
'S+': time.getMilliseconds(),
}
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (time.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (let 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
}
}
[学习来源_js获取昨日、今日、本周、本月](https:
Object.assign
Object.assign(A, handle(B),handle(C))
delete删除属性
delete(this.query['version'])
hasOwnProperty
A.hasOwnProperty('date')