当前位置:网站首页>js常见问题
js常见问题
2022-06-30 09:50:00 【全栈程序员站长】
1.滚动加载
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防止触发多次
if (!this.flagData) return;
this.flagData = false;
this.getSingerList();//请求数据成功后 page+1, this.flagData = true;
}
}2.获取特定对象的值,key忽略大小写
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. 获取地址中的参数值
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.格式化时间
/**
* 格式化时间
* @ date 时间参数,传入字符串
* @ fmt 时间显示格式,‘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.版本号比较
function versionCompare(curV, reqV) {
var arr1 = curV.split('.');
var arr2 = reqV.split('.');
//将两个版本号拆成数字
var maxL = Math.max(arr1.length, arr2.length);
var pos = 0; //当前比较位
var diff = 0; //当前为位比较是否相等
//逐个比较如果当前位相等则继续比较下一位
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;
}
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/101129.html原文链接:https://javaforall.cn
边栏推荐
- KOREANO ESSENTIAL打造气质职场范
- Memorize the text and remember the words. Read the text and remember the words. Read the article and remember the words; 40 articles with 3500 words; 71 articles broke through the words in the middle
- “昆明城市咖啡地图”活动再度开启
- MIT-6874-Deep Learning in the Life Sciences Week5
- ArcGIS Pro脚本工具(5)——排序后删除重复项
- mysql数据库基础:约束、标识列
- Implementation of iterative method for linear equations
- How to deploy deflationary combustion destruction contract code in BSC chain_ Deploy dividend and marketing wallet contract code
- Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled
- Detailed explanation of commissioning methods and techniques
猜你喜欢

CSDN博客运营团队2022年H1总结
[email protected]语音模块+stm32+nfc"/>技能梳理[email protected]语音模块+stm32+nfc

那个程序员,被打了。
[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

“昆明城市咖啡地图”再度开启,咖啡拉近城市距离

记一次实习的经历,趟坑必备(一)

Oracle creates a stored procedure successfully, but the compilation fails

Apple's 5g chip was revealed to have failed in research and development, and the QQ password bug caused heated discussion. Wei Lai responded to the short selling rumors. Today, more big news is here

mysql数据库基础:存储过程和函数
[email protected]+adxl345+电机震动+串口输出"/>技能梳理[email protected]+adxl345+电机震动+串口输出
随机推荐
ArcGIS Pro + PS 矢量化用地规划图
KOREANO ESSENTIAL打造气质职场范
打通供应链 深圳礼品展助跨境电商寻破局之道
Turn to cartoon learning notes
Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled
Implementation of monitor program with assembly language
最新SCI影响因子公布:国产期刊最高破46分!网友:算是把IF玩明白了
"Kunming City coffee map" activity was launched again
The rising star of Goldshell STC box
Deploy lvs-dr cluster
The programmer was beaten.
Koreano essential creates a professional style
Tooltips in the era of touch
Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
IPhone address book import into Excel
MySQL index, transaction and storage engine of database (3)
After recording 7000 IELTS words in 100 sentences, there are only 1043 words (including simple words such as I and you)
WGet -- 404 not found due to spaces in URL
Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述