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..