web建站教程

  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. php入门
    nodejs
    mockjs
    mysql
    织梦cms
    帝国cms
    git教程
js判断当前对象是否为中文
2021年12月16日  浏览(179)
function isChinese(obj) {if (/.*[\u4e00-\u9fa5]+.*$/.test(obj)){return 是中文;}return 不是中文;}var name = 前端入门www建站1231教程var url = http://ipkd.cnvar num = 12345678console.log(name:, isChinese(name))console.log(url:, isChinese(url))console.log(num:, isChinese(num))
阅读全文>>
js对url指定参数进行删除,并返回url
2021年12月16日  浏览(149)
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.split();for (var i = 0; i arr.length; i++) {arr[i] = arr[i].split(=);obj[arr[i][0]] = arr[i][1];};delete obj[name];var url = baseUrl + JSON.stringify(obj).replace(/[\\{\}]/g,).replace(/\:/g,=).replace(/\,/g,);return url}else{return window.location.href;};}//控制台输出con
阅读全文>>
最简单的js数组去重方法
2021年12月16日  浏览(160)
var county =[{name: 鹿城区, value: 8340363, code: 330302},{name: 龙湾区, value: 576804, code: 330303},{name: 瓯海区, value: 14376314, code: 330304},{name: 洞头区, value: 305933, code: 330305},{name: 永嘉县, value: 1034338, code: 330324},{name: 永嘉县, value: 1034338, code: 3303241},{name: 平阳县, value: 1262985, code: 330326},{name: 苍南县, value: 917294, code: 330327},{name: 文成县, value: 211791, code: 330328},{name: 文成县, value: 211791, code: 330328},{name: 泰顺
阅读全文>>
JavaScript开发小技巧之各种时间操作
2021年12月10日  浏览(126)
当前时间 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()); const hour = now.getHours() = 10 ? now.getHours() : (0 + now.getHours()); const miu = now.getMinutes() = 10 ? now.getMinutes() : (0 + now.getMinutes()); const sec = now.getSeconds() = 10 ? now.getSeconds() : (0 + now.getSeconds()); return +year + 年 + (month + 1) + 月 + date + 日 + hour + : + miu
阅读全文>>
JavaScript开发小技巧之各种浏览器操作
2021年12月10日  浏览(156)
滚动到页面顶部 export const scrollToTop = () = { const height = document.documentElement.scrollTop || document.body.scrollTop; if (height 0) { window.requestAnimationFrame(scrollToTop); window.scrollTo(0, height - height / 8); }} 滚动到页面底部 export const scrollToBottom = () = { window.scrollTo(0, document.documentElement.clientHeight); } 滚动到指定元素区域 export const smoothScroll = (element) = { document.querySelector(element).scrollIntoView({ behavior: smooth });}; 获
阅读全文>>
JavaScript开发小技巧之各种设备判断
2021年12月10日  浏览(160)
判断是移动还是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;} 判断是苹果还是android移动设备 export const isAppleMobileDevice = () = { let reg = /iphone|ipod|ipad|Macintosh/i; return reg.test(navigator.userAgent.toLowerCase());} 判断是否是android移动设备 export const isAndroidMobileDevice = () = { return /android/i.test(navigator
阅读全文>>
JavaScript开发小技巧之各种URL操作
2021年12月10日  浏览(120)
获取url参数列表 export const GetRequest = () = { let url = location.search; const paramsStr = /.+\?(.+)$/.exec(url)[1]; // 将 ? 后面的字符串取出来 const paramsArr = paramsStr.split(); // 将字符串以 分割后存到数组中 let paramsObj = {}; // 将 params 存到对象中 paramsArr.forEach(param = { if (/=/.test(param)) { // 处理有 value 的参数 let [key, val] = param.split(=); // 分割 key 和 value val = decodeURIComponent(val); // 解码 val = /^\d+$/.test(val) ? pa
阅读全文>>
JavaScript开发小技巧之各种格式校验
2021年12月10日  浏览(79)
校验身份证号码 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-\u9fa5]/.test(value);} 校验是否为中国大陆的邮政编码 export const isPostCode = (value) = { return /^[1-9][0-9]{5}$/.test(value.toString());} 校验是否为IPV6地址 export const isIPv6 = (str) = { return Boolean(str.match(/:/g)?str.match(/:/g).length=7:false /::/.
阅读全文>>
JavaScript开发小技巧之cookie
2021年12月10日  浏览(160)
设置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 = (key) = { const cookieStr = unescape(document.cookie); const arr = cookieStr.split(; ); let cookieValue = ; for (let i = 0; i arr.length; i++) { const temp = arr[i].split(=); if (temp[0] === key) { cookieValue = temp[1]; break } } return cookieValue}; 删除cookie export const d
阅读全文>>
JavaScript开发小技巧之存储loalStorage
2021年12月10日  浏览(76)
存储loalStorage export const loalStorageSet = (key, value) = { if (!key) return; if (typeof value !== string) { value = JSON.stringify(value); } window.localStorage.setItem(key, value);}; 获取loalStorage export const loalStorageGet = (key) = { if (!key) return; return window.localStorage.getItem(key);}; 删除loalStorage export const loalStorageRemove = (key) = { if (!key) return; window.localStorage.removeItem(key);}; 存储sessionStorage export const sessionStorageSet = (key, value) = { if
阅读全文>>
JavaScript开发小技巧之格式化
2021年12月10日  浏览(200)
数字转化为大写金额 export const digitUppercase = (n) = { const fraction = [角, 分]; const digit = [ 零, 壹, 贰, 叁, 肆, 伍, 陆, 柒, 捌, 玖 ]; const unit = [ [元, 万, 亿], [, 拾, 佰, 仟] ]; n = Math.abs(n); let s = ; for (let i = 0; i fraction.length; i++) { s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, ); } s = s || 整; n = Math.floor(n); for (let i = 0; i unit[0].length n 0; i++) { let p = ; for (let j = 0; j unit[1].length n 0
阅读全文>>
JavaScript开发小技巧之字符串
2021年12月10日  浏览(196)
生成随机字符串 export const randomString = (len) = { let chars = ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz123456789; let strLen = chars.length; let randomStr = ; for (let i = 0; i len; i++) { randomStr += chars.charAt(Math.floor(Math.random() * strLen)); } return randomStr;}; 字符串首字母大写 export const fistLetterUpper = (str) = { return str.charAt(0).toUpperCase() + str.slice(1);}; 手机号中间四位变成* export const telFormat = (tel) = { tel = String(tel); return tel.sub
阅读全文>>
JavaScript开发小技巧之数组技巧
2021年12月10日  浏览(128)
数组乱序 export const arrScrambling = (arr) = { for (let i = 0; i arr.length; i++) { const randomIndex = Math.round(Math.random() * (arr.length - 1 - i)) + i; [arr[i], arr[randomIndex]] = [arr[randomIndex], arr[i]]; } return arr;} 数组扁平化 export const flatten = (arr) = { let result = []; for(let i = 0; i arr.length; i++) { if(Array.isArray(arr[i])) { result = result.concat(flatten(arr[i])); } else { result.push(arr[i]); } } return result;} 数组中获取随机数 export const sample
阅读全文>>
JavaScript开发小技巧之数字操作
2021年12月10日  浏览(198)
生成指定范围随机数 export const randomNum = (min, max) = Math.floor(Math.random() * (max - min + 1)) + min; 数字千分位分隔 export const format = (n) = { let num = n.toString(); let len = num.length; if (len = 3) { return num; } else { let temp = ; let remainder = len % 3; if (remainder 0) { // 不是3的整数倍 return num.slice(0, remainder) + , + num.slice(remainder, len).match(/\d{3}/g).join(,) + temp; } else { // 3的整数倍 return num.slice(0, len).match(/\d{3}/g).join(,)
阅读全文>>
12种数组中常用到的JavaScript技巧
2021年12月10日  浏览(66)
1、 数组去重 ⑴、from()叠加 new Set() 方法 字符串或数值型数组的去重可以直接使用from方法。 var plants = [Saturn, Earth, Uranus, Mercury, Venus, Earth, Mars, Jupiter];var uniquePlants = Array.from(new Set(plants)); console.log(uniquePlants); // [ Saturn, Earth, Uranus, Mercury, Venus, Mars, Jupiter ] ⑵、 spread 操作符() 扩展运算符是ES6的一大创新,还有很多强大的功能。 var plants = [Saturn, Earth, Uranus, Mercury, Venus, Earth, Mars, Jupite
阅读全文>>
前端常用的49个JavaScript方法
2021年12月10日  浏览(90)
1、输入一个值,返回其数据类型** function type(para) { return Object.prototype.toString.call(para)} 2、数组去重 function unique1(arr) { return [...new Set(arr)]}function unique2(arr) { var obj = {}; return arr.filter(ele = { if (!obj[ele]) { obj[ele] = true; return true; } })}function unique3(arr) { var result = []; arr.forEach(ele = { if (result.indexOf(ele) == -1) { result.push(ele) } }) return result;} 3、字符串去重 String.prototype.unique = function () { var obj = {},
阅读全文>>
20个JavaScript开发小技巧
2021年12月08日  浏览(104)
1. 初始化数组 如果想要初始化一个指定长度的一维数组,并指定默认值,可以这样: const array = Array(6).fill(); // [, , , , , ] 如果想要初始化一个指定长度的二维数组,并指定默认值,可以这样: const matrix = Array(6).fill(0).map(() = Array(5).fill(0)); // [[0, 0, 0, 0, 0],// [0, 0, 0, 0, 0],// [0, 0, 0, 0, 0],// [0, 0, 0, 0, 0],// [0, 0, 0, 0, 0],// [0, 0, 0, 0, 0]] 2. 数组求和、求最大值、最小值 const array = [5,4,7,8,9,2]
阅读全文>>
echarts地图给每个区域添加不同颜色
2021年12月08日  浏览(179)
echarts地图给每个区域添加不同颜色,在geo级下新增regions数组,每个数据一个区域。 geo: {map: 中国各省市县形状,layoutCenter: [50%, 50%],layoutSize: 90%,roam: true, //是否允许缩放mapLocation: {width: 110%,height: 97%},label: {normal: { //静态的时候展示样式show: true, //是否显示地图省份得名称textStyle: {color: #fff,fontSize: 12}},emphasis: { //动态展示的样式color: #fff,},},//默认颜色itemStyle: {normal: {areaColor: #091233,bor
阅读全文>>
如何解决跨域
2021年12月06日  浏览(95)
1、跨文档通信 API:window.postMessage() 调用postMessage方法实现父窗口 A.com 向子窗口 B.com 发消息(子窗口同样可以通过该方法发送消息给父窗口。主要解决以下几种场景 页面和其打开的新窗口的数据传递 多窗口之间消息传递 页面与嵌套的iframe消息传递 上面三个场景的跨域数据传递 // 父窗口打开一个子窗口var openWindow = window.open(https://ipkd.cn, hello); // 父窗口向子窗口发消息(第一个参数
阅读全文>>
js查找多维数组中的存在某个值,并全部删除
2021年12月03日  浏览(153)
var arr1=[{id:1, name:123, age:12},{id:2, name:1223, age:12},{id:3, name:123, age:12},{id:4, name:1223, age:12}]function delArrVal(arr,val){ for(let i=0;iarr.length;i++){ if(typeof arr[i].name==val){ arr.splice(i,1) i--; } } return arr;}delArrVal(arr1,123) 扩展方法 1、数据去重 function deletArrE(userInfoLS, examNo) {let list = [...userInfoLS];let result = [];let obj = {};for (let i = 0; i list.length; i++) {if (!obj[list[i][examNo]]) {result.push(list[i]);obj[list[i].examNo] = true;}}re
阅读全文>>

常用标签