var text = '你是我的家,我是你的他,今年十一去见他,一起去看他'; //把所有“他”替换成“它” var result = text.replace(/\他/g,&
Ps:Longhand表示常规写法,Shorthand表示简写形式 1、当同时声明多个变量时,可简写成一行 //Longhand let x; let y = 20; //Shorthand let x, y = 20; 2、利用解构,可为
阻止冒泡事件 export const stopPropagation = (e) => { e = e || window.event; if(e.stopPropagation) { // W3C阻止冒泡方法 e.stopProp
当前时间 export const nowTime = () => { const now = new Date(); const year = now.getFullYear(); const month = now.getMont
滚动到页面顶部 export const scrollToTop = () => { const height = document.documentElement.scrollTop || document.body.scrollT
判断是移动还是pc设备 export const isMobile = () => { if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerr
获取url参数列表 export const GetRequest = () => { let url = location.search; const paramsStr = /.+\?(.+)$/.exec(url)[1]; //
校验身份证号码 export const checkCardNo = (value) => { let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; return reg.test
设置cookie export const setCookie = (key, value, expire) => { const d = new Date(); d.setDate(d.getDate() + expire); do
存储loalStorage export const loalStorageSet = (key, value) => { if (!key) return; if (typeof value !== 'string'
数字转化为大写金额 export const digitUppercase = (n) => { const fraction = ['角', '分']; const digit = [ '零&
生成随机字符串 export const randomString = (len) => { let chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz123456789
数组乱序 export const arrScrambling = (arr) => { for (let i = 0; i < arr.length; i++) { const randomIndex = Math.round
生成指定范围随机数 export const randomNum = (min, max) => Math.floor(Math.random() * (max – min + 1)) + min; 数字千分位分隔 export co
1、数组去重 ⑴、from()叠加new Set()方法 字符串或数值型数组的去重可以直接使用from方法。 var plants = ['Saturn', 'Earth', 'Uranus'
