版权声明:转发博客 请注明出处 否则必究 https://blog.csdn.net/lucky541788/article/details/82082013
大小写转换
.toUpperCase();//转换大写
.toLowerCase();//转换小写
URI编解码
URI编码(给服务器看的)
var text1="https://www.baidu.com/?tn=78000241_12_hao_pg中国";
var encode=encodeURIComponent(text1);
console.log(encode); //https%3A%2F%2Fwww.baidu.com%2F%3Ftn%3D78000241_12_hao_pg%E4%B8%AD%E5%9B%BD
URI解码(给人看的,通过它可以获取一些网页内容)
var text2="https%3A%2F%2Fwww.baidu.com%2F%3Ftn%3D78000241_12_hao_pg%E4%B8%AD%E5%9B%BD";
var decode=decodeURIComponent(text2);
console.log(decode); //https://www.baidu.com/?tn=78000241_12_hao_pg中国
定时器
定时器
var timer=null;
timer=setInterval(function(){//设置定时器
alert(1);
},1000);
clearInterval(timer);//清除定时器
一次定时器
var timer=null;
timer=setTimeout(function(){//设置一次定时器
alert(1);
},1000);
clearTimeout(timer);//清除一次定时器
定时器节流
1、函数节流
var timer=null;
window.onresize=function () {
clearTimeout(timer);
timer=setTimeout(function () {
myfunction();
},200);
}
2、闭包节流
function throttle(fn, delay) {
var timer=null;
return function () {
clearInterval(timer);
timer=setInterval(fn,delay);
}
}
window.onresize=throttle(function () {
console.log(1);
},400);