当前位置:网站首页>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
边栏推荐
- Es common curl finishing
- MySQL index, transaction and storage engine of database (1)
- R语言aov函数进行重复测量方差分析(Repeated measures ANOVA、其中一个组内因素和一个组间因素)、分别使用interaction.plot函数和boxplot对交互作用进行可视化
- Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
- The famous painter shiguoliang's "harvest season" digital collection was launched on the Great Wall Digital Art
- 苹果5G芯片被曝研发失败,QQ密码bug引热议,蔚来回应做空传闻,今日更多大新闻在此...
- I found a wave of "alchemy artifact" in the goose factory. The developer should pack it quickly
- mysql数据库基础:TCL事务控制语言
- Jinbei LT6 is powerful in the year of the tiger, making waves
- SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
猜你喜欢

mysql数据库基础:约束、标识列

ArcGIS Pro脚本工具(5)——排序后删除重复项

2022 Season 6 perfect children's model toxon division finals came to a successful conclusion

KOREANO ESSENTIAL打造气质职场范

South China Industrial Group launched digital economy and successfully held the city chain technology conference

Koreano essential creates a professional style

Implementation of monitor program with assembly language

《锦绣中华》中老年公益文旅游-走进佛山敬老院

“昆明城市咖啡地图”活动再度开启

马斯克推特粉丝过亿了,但他在线失联已一周
随机推荐
移植完整版RT-Thread到GD32F4XX(详细)
Use keil5 software to simulate and debug gd32f305 from 0
Harvester ch1 of CKB and HNS, connection tutorial analysis
Setting up the d2lbook environment for Li Mu's "hands on learning and deep learning"
Notes on numerical calculation - iterative solution of linear equations
Arm新CPU性能提升22%,最高可组合12核,GPU首配硬件光追,网友:跟苹果的差距越来越大了...
"Kunming City coffee map" activity was launched again
OSError: [Errno 28] No space left on device
记一次实习的经历,趟坑必备(一)
从0使用keil5软件仿真调试GD32F305
Compétences Comb 27 @ Body sense Manipulator
Action bright: take good care of children's eyes together -- a summary of the field investigation on the implementation of action bright in Guangxi
A brief introduction to database mysql
R语言aov函数进行重复测量方差分析(Repeated measures ANOVA、其中一个组内因素和一个组间因素)、分别使用interaction.plot函数和boxplot对交互作用进行可视化
GD32 RT-Thread RTC驱动函数
South China Industrial Group launched digital economy and successfully held the city chain technology conference
Compare the maximum computing power of the Cenozoic top ant s19xp and the existing s19pro in bitland
ArcGIS Pro scripting tool (5) - delete duplicates after sorting
June training (day 30) - topology sorting
Implementation of monitor program with assembly language