当前位置:网站首页>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
边栏推荐
- Gd32 RT thread flash driver function
- GeoffreyHinton:我的五十年深度学习生涯与研究心法
- Input a decimal data, convert to 8, using the sequence stack
- "Kunming City coffee map" was opened again, and coffee brought the city closer
- South China Industrial Group launched digital economy and successfully held the city chain technology conference
- ArcGIS Pro脚本工具(5)——排序后删除重复项
- Node environment configuration
- The human agent of kDa, Jinbei kd6, takes you to explore the metauniverse
- 如何解决跨域
- Leetcode question brushing (I) -- double pointer (go Implementation)
猜你喜欢

WGet -- 404 not found due to spaces in URL

Basic MySQL operation commands of database

ArcGIS Pro + PS 矢量化用地规划图

Using LVM to resize partitions

Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development

Kernel linked list (general linked list) "list.h" simple version and individual comments

Why can't you rob scientists of NFT

马斯克推特粉丝过亿了,但他在线失联已一周

The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art

“昆明城市咖啡地圖”活動再度開啟
随机推荐
Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
【Rust日报】2021-01-23 几个新库发布
June training (day 30) - topology sorting
MySQL index, transaction and storage engine of database (3)
Configure Yii: display MySQL extension module verification failed
打通供应链 深圳礼品展助跨境电商寻破局之道
技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled
Gd32 RT thread DAC driver function
Curl --- the request fails when the post request parameter is too long (more than 1024b)
Overview of currency
Dyson design award, changing the world with sustainable design
如何解决跨域
逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展
Skill combing [email protected] voice module +stm32+nfc
CVPR 2022 | 清华&字节&京东提出BrT:用于视觉和点云3D目标检测的桥接Transformer
ArcGIS Pro脚本工具(6)——修复CAD图层数据源
Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
Gd32 RT thread ota/bootloader driver function
Koreano essential creates a professional style
The rising star of Goldshell STC box