当前位置:网站首页>JS FAQs
JS FAQs
2022-06-30 10:39:00 【Full stack programmer webmaster】
1. Scroll load
function onScroll() {
if (this.curPage > this.totalPage) return;
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
if (scrollTop + windowHeight > scrollHeight - 100) {
// flagData Prevent multiple triggers
if (!this.flagData) return;
this.flagData = false;
this.getSingerList();// After successful data request page+1, this.flagData = true;
}
}
2. Get the value of a specific object ,key Ignore case
let options={
shareUserId:123,
}
// let shareUserId=options.shareUserid||options.shareUserId||options.shareUserID;
for (let item in options){
if(item.toLowerCase()=='shareuserid'){
let shareUserId=options[item];
console.log(shareUserId);//123
}
}
3. Get the parameter value in the address
function getUrlParam(name, url) {
if (!url) url = location.href;
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(url);
return results == null ? null : results[1];
}
4. Format time
/**
* Format time
* @ date Time parameters , Incoming string
* @ fmt Time display format ,‘yyyy-MM-dd hh:mm:ss’
*/
function formatDate(time, fmt) {
if(!time) return '';
var date = new Date(time);
var o = {
'y+': date.getFullYear(),
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
};
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
var str = o[k] + '';
fmt = fmt.replace(RegExp.$1, (str.length === 1) ? ('0' + str) : str);
}
};
return fmt;
}
5. Version number comparison
function versionCompare(curV, reqV) {
var arr1 = curV.split('.');
var arr2 = reqV.split('.');
// Split the two version numbers into numbers
var maxL = Math.max(arr1.length, arr2.length);
var pos = 0; // Current comparison bit
var diff = 0; // Whether the current bit comparison is equal
// Compare one by one. If the current bits are equal, continue to compare the next bit
while (pos < maxL) {
diff = parseInt(arr1[pos]||0) - parseInt(arr2[pos]||0);
if (diff != 0) break;
pos++;
}
if (diff >= 0) {
return true;
} else {
return false;
}
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/101129.html Link to the original text :https://javaforall.cn
边栏推荐
- KOREANO ESSENTIAL打造气质职场范
- CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
- 如何解决跨域
- 转卡通学习笔记
- Dyson design award, changing the world with sustainable design
- "Kunming City coffee map" was opened again, and coffee brought the city closer
- Es common curl finishing
- 腾讯云数据库工程师能力认证重磅推出,各界共话人才培养难题
- Musk has more than 100 million twitter fans, but he has been lost online for a week
- The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art
猜你喜欢
Android 开发面试真题进阶版(附答案解析)
The latest SCI impact factor release: the highest score of domestic journals is 46! Netizen: I understand if
机器学习面试准备(一)KNN
[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled"/>
技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled
Jump table introduction
[email protected] intelligent instrument teaching aids based on 51 series single chip microcomputer"/>
Skill combing [email protected] intelligent instrument teaching aids based on 51 series single chip microcomputer
6. Redis new data type
[email protected] control a dog's running on OLED"/>
Skill combing [email protected] control a dog's running on OLED
Musk has more than 100 million twitter fans, but he has been lost online for a week
mysql数据库基础:视图、变量
随机推荐
The programmer was beaten.
Jinbei LT6 is powerful in the year of the tiger, making waves
滴滴开源敏捷测试用例管理平台!
安徽《合肥市装配式建筑施工图审查设计深度要求》印发;河北衡水市调整装配式建筑预售许可标准
TypeScript–es5中的类,继承,静态方法
苹果5G芯片被曝研发失败,QQ密码bug引热议,蔚来回应做空传闻,今日更多大新闻在此...
Jump table introduction
How to seize the opportunity of NFT's "chaos"?
SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
ArcGIS PRO + PS vectorized land use planning map
【Rust每周一库】num-bigint - 大整数
Go -- standard library sort package
逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展
MATLAB image histogram equalization, namely spatial filtering
Android 开发面试真题进阶版(附答案解析)
Leetcode question brushing (III) -- binary search (go Implementation)
Leetcode question brushing (I) -- double pointer (go Implementation)
历史上的今天:微软收购 PowerPoint 开发商;SGI 和 MIPS 合并
Getting started with X86 - take over bare metal control
nvm、nrm、npx使用(安装、基本命令、参数、curl、wget)