工作随笔

1)时间格式转化
new Date().format(“yyyy-MM-dd”).replace(/[-]/g,’’);
replace(/[,]/g,’’) =>过滤中括号中的字符

2)数组项顺序调换
function swapArr(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
}

3)字符串转布尔值
Boolean(a)

4)react渲染富文本

5)背景图片自适应
{
background-image:url(images/yuantiao.jpg);
background-repeat:no-repeat;
background-size:100% 100%;
-moz-background-size:100% 100%;
}

6)git关联远程仓库
git branch --set-upstream-to=origin/master mast)

7)一串数字转化为时间
const transferTime = (num) => {
let jsonDate = new Date(parseInt(num));
Date.prototype.format = function (format){
let o = {
“y+”: this.getFullYear(),
“M+”: this.getMonth()+1,
“d+”: this.getDate(),
“h+”: this.getHours(),
“m+”: this.getMinutes(),
“s+”: this.getSeconds()
};
if(/(y+)/.test(format)){
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(let k in o){
if(new RegExp("("+k+")").test(format)){
format = format.replace(RegExp.$1, RegExp.$1.length == 1?o[k] : ("" + o[k]).substr("" + o[k].length));
}
}
return format;
};
let newDate = jsonDate.format(“yyyy-MM-dd”);
return newDate
}
const transferTime = (timeStamp) => {
var date = new Date();
date.setTime(timeStamp * 1000);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? (‘0’ + m) : m;
var d = date.getDate();
d = d < 10 ? (‘0’ + d) : d;
var h = date.getHours();
h = h < 10 ? (‘0’ + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? (‘0’ + minute) : minute;
second = second < 10 ? (‘0’ + second) : second;
return y + ‘-’ + m + ‘-’ + d+’ ‘+h+’:’+minute+’:’+second;
};

8)批量删除数组中知道下标的项
const selectedMerchandise = [1,2,3,4,5,6,7,8,9];
const selectIndex = [1,3,5];
const newIndex = selectIndex.sort().map((val, idx) => {
return val - idx
})
newIndex.forEach(i => {
selectedMerchandise.splice(i, 1)
})

9)全局替换
replace(/旧的字段/g, ‘新的字段l’))

10)输入框只允许输入数字
οninput=“value=value.replace(/[^\d]/g,’’)”

11)js获取PHP中使用的字段
var xxx= <?php echo json_encode($output['xxx']);?>’
console.log(xxx);

  1. 防止自动填充表单
    autocomplete=“new-password”
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值