随笔分类 -  js

摘要:1 // 参数dom为html dom节点 2 // 参数key为需模糊查询的名称字段 3 function queryClassNode(dom, key) { 4 let collectArray = []; 5 for (let i = 0; i < dom.childNodes.length 阅读全文
posted @ 2024-01-22 11:16 PromiseOne 阅读(157) 评论(0) 推荐(0) 编辑
摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>切片上传</title> </head> <body> <script src="https://cdn.bootcdn.net/ajax/libs/spark 阅读全文
posted @ 2023-05-29 11:40 PromiseOne 阅读(28) 评论(0) 推荐(0) 编辑
摘要:1.实例的__proto__ 属性 非标准ie浏览器不支持 let arr = [1,2,3]; console.log('__proto__',arr.__proto__ Array.prototype)2.实例的 constructorlet arr = [1,2,3];console.log( 阅读全文
posted @ 2022-09-28 20:21 PromiseOne 阅读(43) 评论(0) 推荐(0) 编辑
摘要:// 写法一 let [cache, cache2] = await Promise.all([cachePromise, cachePromise2]); // 写法二 let Promise= cachePromise(); let Promise2= cachePromise2(); let 阅读全文
posted @ 2022-08-17 17:26 PromiseOne 阅读(179) 评论(0) 推荐(0) 编辑
摘要:Object.keys(Array.from(Array(100))) 阅读全文
posted @ 2022-07-29 17:33 PromiseOne 阅读(307) 评论(0) 推荐(0) 编辑
摘要:function getCaption(obj, text){ let index = obj.lastIndexOf(text) + text.length-1; obj = obj.substring(index+1,obj.length); return obj; } let str=" 执法 阅读全文
posted @ 2022-03-30 14:17 PromiseOne 阅读(3111) 评论(0) 推荐(0) 编辑
摘要:let array1 = [ {'Num': 'A ', 'Name': 't1 '}, {'Num': 'B', 'Name': 't2'}, {'Num': 'C ', 'Name': 't3 ', age: '222'}, {'Num': 'D', 'Name': 't4 ', age: '3 阅读全文
posted @ 2021-10-08 16:16 PromiseOne 阅读(1718) 评论(0) 推荐(0) 编辑
摘要:flatten(arr) { return [].concat(...arr.map(item => { if (item.children) { let arr = [].concat(item, ...this.flatten(item.children)); delete item.child 阅读全文
posted @ 2021-10-08 15:12 PromiseOne 阅读(705) 评论(0) 推荐(0) 编辑
摘要:01-随机获取布尔值 Math.random创建一个介于0和1之间的随机数,然后我们检查它是否大于或小于0.5。这意味着有50/50的机会会得到对或错。 const getRandomBoolean = () => Math.random() >= 0.5; 02-检查日期是否为周末 通过此功能,你 阅读全文
posted @ 2021-06-29 16:58 PromiseOne 阅读(56) 评论(0) 推荐(0) 编辑
摘要:校验是否正确的网址:/^((http|https):\/\/)([\w-]+\.)+[\w-]+([\w-./?%&=]*)?$/ 数字:/^[0-9]*$/ 1~9的数字:/^[1-9]\d*$/ 不能输入特殊字符:/[^u4e00-u9fa5\w]/ 不能输入表情:/^[A-Za-z0-9\u4 阅读全文
posted @ 2021-06-28 14:08 PromiseOne 阅读(721) 评论(0) 推荐(0) 编辑
摘要:function arrayhandle(arr){ arr.map(item => { // 对数据进行处理 item.label = item.title; if(item.children && item.children.length) { arrayhandle(item.children 阅读全文
posted @ 2021-05-24 17:26 PromiseOne 阅读(1938) 评论(0) 推荐(0) 编辑
摘要:不管触发多少次事件,都会等到事件触发n秒后才会执行,如果在事件触发的 n 秒内 又触发了这个事件,那么就以新的事件的时间为准重新计算,总之,就是要等你触发事件 n 秒内 不再触发事件,才会执行,一般用在用户表单输入实时搜索上 1 function debounce(fn, wait) { 2 let 阅读全文
posted @ 2021-03-25 17:21 PromiseOne 阅读(58) 评论(0) 推荐(0) 编辑
摘要:使用es5 Array.reduce()方法实现 1.语法 2.参数 3.实现代码 1 //树形数据 2 let child = [ 3 { 4 name: "文件1", 5 pid: 1, 6 id: 10001 7 }, 8 { 9 name: "文件2", 10 pid: 1, 11 id: 阅读全文
posted @ 2021-03-25 16:23 PromiseOne 阅读(473) 评论(0) 推荐(0) 编辑
摘要:1 // 示例urlStr:http://html/index.html?user=admin&pwd=123456 2 3 function getRequest(urlStr) { 4 if (typeof urlStr == "undefined") { 5 var url = decodeU 阅读全文
posted @ 2020-07-14 17:27 PromiseOne 阅读(200) 评论(0) 推荐(0) 编辑
摘要:function toThousands(num) { num = (num || 0).toString(); let number = 0, floatNum = '', intNum = ''; // 判断是否有小数位,有则截取小数点后的数字 if (num.indexOf('.') > 0) 阅读全文
posted @ 2020-07-10 14:35 PromiseOne 阅读(492) 评论(0) 推荐(0) 编辑
摘要:1 function fnInitScreen() { 2 var html = document.getElementsByTagName("html")[0]; 3 var width = window.innerWidth; 4 var font_size = 0; 5 font_size = 阅读全文
posted @ 2020-06-18 10:16 PromiseOne 阅读(1048) 评论(0) 推荐(0) 编辑
摘要:let arr = []; let obj = {}; Object.prototype.toString.call(arr) '[object Object]' //判断对象 返回true Object.prototype.toString.call(obj) '[object Array]' / 阅读全文
posted @ 2020-06-04 11:29 PromiseOne 阅读(337) 评论(0) 推荐(0) 编辑
摘要:1 let arr= ['baidu', 'google', 'taobao']; 2 try{ 3 arr.forEach(item=>{ 4 if(item == 'google'){ 5 throw new Error(); 6 } 7 }) 8 }catch(e){ 9 return; 10 阅读全文
posted @ 2020-06-02 19:05 PromiseOne 阅读(1620) 评论(0) 推荐(0) 编辑
摘要:原因:JavaScript 中对象的赋值是默认引用赋值的(两个对象指向相同的内存地址) 解决方案1: 用 JSON.stringify 把对象转换成字符串,再用 JSON.parse 把字符串转换成新的对象 function deepClone(obj){ return JSON.parse(JSO 阅读全文
posted @ 2020-06-02 15:44 PromiseOne 阅读(2589) 评论(0) 推荐(0) 编辑
摘要:1 let arr= ['baidu', 'google', 'taobao']; 2 3 console.log(arr.includes('baidu')); //true 4 console.log(arr.includes('baidu1')); //false 阅读全文
posted @ 2020-02-19 10:42 PromiseOne 阅读(30961) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示