Js一键复制文本内容
一个便捷且炫酷的一键复制方法// text为你要复制的内容 function copyText(text) { var input = document.createElement("input") // 创建input对象 input.value = text // 设置复制内容 document.body.appendChild(input) //
一个便捷且炫酷的一键复制方法// text为你要复制的内容 function copyText(text) { var input = document.createElement("input") // 创建input对象 input.value = text // 设置复制内容 document.body.appendChild(input) //
indexOf()函数可以判断一个元素是否在某个数组中存在,假设存在则返回该元素所在数组位置的索引值。用法const a = 'aaa' const arr = ['aaa','bbb','ccc','ddd'] let index = arr.indexOf(a) console.log(index) // 输出结果为0进阶用法懒得写...有时间再写吧...
作用window.location.replace()函数跳转的页面将不再保存到历史URL中试验当你从a页面用普通得跳转方式跳转到b页面,再从b页面用window.location.replace()函数跳转到c页面,然后你从c页面返回上一页将会直接跳转到a页面,b页面并不会保存于浏览器历史记录中用法window.location.replace('```这里写你要跳转的URL```')
多个条件的判断我们可以在数组中存储多个值,并且我们可以使用数组的includes方法。//普通写法 if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') { //logic } //简写方法 if (['abc', 'def', 'ghi', 'jkl'].includes(x)) { //logic }If true ... e
1、单行If-Else语句你可能熟悉这样的常规if-else语句:if (10 < 100) { console.log("True"); } else { console.log("False"); }输出True但是,你知道吗,你可以通过使用三元运算符,以更短,更简洁的方式编写上面的代码?10 <100 ? console.log(&
splice()方法const arr = [1, 2, 3, 4, 5] const newArr = arr.splice(0,3) // 截取索引值0-3位的值 console.log('newArr:' + newArr) console.log('arr:' + arr) // 控制台输出结果 // newArr:[1, 2, 3] // arr:[4, 5]控制台打印出 arr 的结果
axios中文官网地址GET 请求axios.get('接口url', { params: { 携带参数 }, headers: { 'content-type': 'application/x-www-form-urlencoded', 'Authorization': this.$sto
今天晚饭时在犹豫吃什么随手写的一个抽签函数,有选择恐惧症的小伙伴可以直接复制到控制台使用。 function randomRange(min, max) { return Math.floor(Math.random() * (max - min)) + min; } let result = randomRange(0, 1000); if (result % 2) { con
HTML代码<nav> <a class="nav-link" href="index.php">首页</a> <a class="nav-link" href="shop.php">商城</a> <a class="n
JavaScript中的Array对象与其他编程语言中的数组一样,可以将多个项目的集合存储在单个变量名下,并具有用于执行常见数组操作的成员。 声明数组有两种不同的方式可以声明数组。使用new Array通过new Array,我们可以指定希望存在于数组中的元素,如下所示:const fruits = new Array('Apple', 'Banana'); console.log(fruits