防抖
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <input type="submit" value="send" onclick="send()"> </body> <script> function send() { debounce(() => { console.log('1') }, 2000)() } const debounce = (fn, delay) => { let timer = null; return () => { clearTimeout(timer); timer = setTimeout(() => { fn.apply(this) }, delay) } } </script> </html>
时间转化
<!DOCTYPE html> <html> <head> <title></title> </head> <body> </body> <script type="text/javascript"> // 将秒化为时分秒 formateSeconds(endTime) { let secondTime = parseInt(endTime); //将传入的秒的值转化为Number let min = 0; // 初始化分 let h = 0; // 初始化小时 let result = ""; if (secondTime > 60) { //如果秒数大于60,将秒数转换成整数 min = parseInt(secondTime / 60); //获取分钟,除以60取整数,得到整数分钟 secondTime = parseInt(secondTime % 60); //获取秒数,秒数取佘,得到整数秒数 if (min > 60) { //如果分钟大于60,将分钟转换成小时 h = parseInt(min / 60); //获取小时,获取分钟除以60,得到整数小时 min = parseInt(min % 60); //获取小时后取佘的分,获取分钟除以60取佘的分 } } result = `${h.toString().padStart(2, "0")}:${min.toString().padStart(2, "0")}:${secondTime.toString().padStart(2, "0")}`; return result; }, // 将时分秒化为秒 formSeconds(times){ let arr = times.split(":"); let s = arr[2]; let m = arr[1]; let h = arr[0]; let m1 = m<10?m.replace(/\b(0+)/gi,""):m; let h1 = h<10?h.replace(/\b(0+)/gi,""):h; return m1*60+Number(h1)+Number(s) }, </script> </html>
简易搜索
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <input type="text" id="int"> </body> <script> let list = ["示例1","示例12","示例5","示例56"]; document.querySelector('#int').onchange=function(e){ console.log(search(e.target.value)); } function search(val) { if (val) { return list.filter(function (item) { return Object.keys(item).some(function (key) { return String(item[key]).toLowerCase().indexOf(val) > -1 }) }) } return list } </script> </html>
持续更新。。。