复制到剪切板

copy(val) { let oInput = document.createElement("input"); oInput.value = val; document.body.appendChild(oInput); oInput.select(); document.execCommand("Copy"); this.$message({ message: "复制成功", type: "success", }); oInput.remove(); },

read more..

正则

数字 data = data.replace(/[^\.\d]/g, "") // 数字 data = data.replace(".", "") // 去掉小数点 小数两位 data = data.replace(/[^\.\d]/g,"") // 数字 data = data.replace(/^(\-)*(\d+)\.(\d\d).*$/,"$1$2.$3") // 小数点后 视频图片 var reg = /\.(png|jpg|gif|jpeg|webp)$/; /(mp4|avi|mov|mkv|flv)$/ reg.test(fileName) 去除空格  text = text.re...

read more..

JS-Cookie

function getCookie(cookie_name) { var allcookies = document.cookie; var cookie_pos = allcookies.indexOf(cookie_name); if (cookie_pos !== -1) { cookie_pos = cookie_pos + cookie_name.length + 1; var cookie_end = allcookies.indexOf(";", cookie_pos); if (cookie_end === -1) { cookie_end = allcookies.len...

read more..

JS常用方法

加号运算符 // 可以做到转换格式 let a = '12' let b = + a + 12; let c = a - 0 + 12 let d = a + 12; console.log(b); // 24 console.log(c); // 24 console.log(d); // 1212 动态绑定属性 // 在with中可以操作对象的每一项 let tom = { name: "tom", height: 170, sex: "男" } with(tom){ height++ console.log(height); // 171 console.log(name); // tom } 函...

read more..

JS判断是否在当前页面

var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null; var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange'); var onVisibilityChange = function () { if (!document[hiddenProperty]) { do...

read more..

JS获取URL参数

function GetQueryValue(key) { // 获取?后面的参数 var query = decodeURI(window.location.search.substring(1)); // 通过 & 切割为数组 ["naem=tom"] var queryArr = query.split("&"); // 循环遍历 在将每一项通过 = 切割 做判断key for (var i = 0; i < queryArr.length; i++) { var pair = queryArr[i].split("="); if (pa...

read more..

JS笔记

直接返回时间戳:Date.now(); 当前时间 let newDate = new Date(); let strData = `${newDate.getFullYear()}-${newDate.getMonth() + 1}-${newDate.getDate()} ${newDate.getHours()}:${newDate.getMinutes()}:${newDate.getSeconds()}` console.log(strData); VIDEO倍速:playbackRate

read more..