2024年07月31日 设置cookie export const setCookie = (key, value, expire) => { const d = new Date(); d.setDate(d.getDate() + expire); document.cookie = `${key}=${value};expires=${d.toUTCString()}` }; 读取cookie export const getCookie

2024年07月31日 校验身份证号码 export const checkCardNo = (value) => { let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; return reg.test(value); }; 校验是否包含中文 export const haveCNChars => (value) => { return /[\u4e00-\u9f

2024年07月31日 获取url参数列表 export const GetRequest = () => { let url = location.search; const paramsStr = /.+\?(.+)$/.exec(url)[1]; // 将 ? 后面的字符串取出来 const paramsArr = paramsStr.split('&'); // 将字符串以 & 分割后存到数组中 let

2024年07月31日 判断是移动还是pc设备 export const isMobile = () => { if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i))) { return 'mobile'; } return 'desktop';

2024年07月31日 滚动到页面顶部 export const scrollToTop = () => { const height = document.documentElement.scrollTop || document.body.scrollTop; if (height > 0) { window.requestAnimationFrame(scrollToTop); window.scrollTo(0, height - heig

2024年07月31日 当前时间 export const nowTime = () => { const now = new Date(); const year = now.getFullYear(); const month = now.getMonth(); const date = now.getDate() >= 10 ? now.getDate() : ('0' + now.getDate()); c

2024年07月31日 var county =[ {name: "鹿城区", value: 8340363, code: "330302"}, {name: "龙湾区", value: 576804, code: "330303"}, {name: "瓯海区", value: 14376314, code: "330304"}, {name: "洞头

2024年07月30日 1、删除当前页面的url中flag参数 function urlDel(name){ var url = window.location; var baseUrl = url.origin + url.pathname + "?"; var query = url.search.substr(1); if (query.indexOf(name)>-1) { var obj = {} var arr = query

2024年07月30日 function isChinese(obj) { if (/.*[\u4e00-\u9fa5]+.*$/.test(obj)){ return '是中文'; } return '不是中文'; } var name = '前端入门www建站1231教程' var url = 'http://lmcjl.com' var num = 12345678 console.log(

2024年07月30日 js用正则同时删除第一个和最后一个斜杠,如果只有第一个斜杠或只有最后一个斜杠也可以用。 方法一: let arr = ["图像","报告","修改"]; let name = ''; for(let i=0; i<arr.length; i++){ name += arr[i] + '/' }; name = name.replace(/^\/|\/$/g, ""); console.log('结果

2024年07月30日 flat()方法会按照一个可指定的深度递归遍历数组,并将所有元素与遍历到的子数组中的元素合并为一个新数组返回。flat除了有扁平化嵌套数组之外还可以扁平化空项。 实例: let a = [1,2,3,[4,5,[6,7]]] console.log(a.flat()) //默认扁平一层 console.log(a.flat(2)) //扁平二层 //输出结果 [1, 2, 3, 4, 5, Array(2)] [1, 2, 3, 4, 5, 6, 7]

2024年07月30日 1、中文字符 var pattern = /[\u4e00-\u9fa5]/; var str = "建站教程"; console.log(pattern.test(str)); 2、双字节字符 var pattern = /[^\x00-\xff]/; var str = "建站教程ipkd"; console.log(pattern.test(str)); 3、空白行 var patt

2024年07月30日 阻止冒泡事件 export const stopPropagation = (e) => { e = e || window.event; if(e.stopPropagation) { // W3C阻止冒泡方法 e.stopPropagation(); } else { e.cancelBubble = true; // IE阻止冒泡方法 } } 防抖函

2024年07月30日 用到了递归思路,从第一层一直去循环数组,从而获取当前数组是几维数组,代码如下: var arr = [1,2,3,[1,2,3,1,3,[1,2,3,6,4,[1,2,3,1]]],2] var arrNum = 1; //方法: function multiArr(arr){ for (i=0;i<arr.length;i++){ if(arr[i] instanceof Array){ arrNum++; arr = ar

2024年07月30日 Ps:Longhand表示常规写法,Shorthand表示简写形式 1、当同时声明多个变量时,可简写成一行 //Longhand let x; let y = 20; //Shorthand let x, y = 20; 2、利用解构,可为多个变量同时赋值 //Longhand let a, b, c; a = 5; b = 8; c = 12; //Shorthand let [a, b, c] = [5, 8, 1

最新内容