![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
javascript
樊小烦
这个作者很懒,什么都没留下…
展开
-
promise实现红绿灯
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Doc原创 2021-04-01 14:50:47 · 180 阅读 · 0 评论 -
长轮循
长轮循:请求数据,待数据返回之后,再次请求 function http(){ let time = parseInt(Math.random()*5)*1000; return new Promise((resolve, reject) => { setTimeout(() => { resolve(time); }, time); }) } f原创 2021-03-30 14:08:05 · 83 阅读 · 0 评论 -
Reduce方法
arr.reduce(function(total, curValue, curIndex, arr), initvalue)//total 有initValue,仅输出一次initValue;无initValue,仅输出一次输出arr[0]1.有初始值参数var numbers = [15.5, 2.3, 1.1, 4.7];numbers.reduce((total, curValue, curIndex, arr) => { console.log(total); c原创 2021-03-24 11:55:43 · 1280 阅读 · 0 评论 -
for 与forEach中return用法
在函数体中for循环可以使用returnfunction dd(){ for(var i=0;i<4;i++){ return 'fanxuejing'; }console.log('aaa');}dd() //fanxuejingfunction test(){ for(var i = 0; i < 5; i++){ if(i > 3) { console.log(i) return原创 2021-03-23 10:01:08 · 857 阅读 · 0 评论 -
逻辑思路
请求一个方法,可能成功,可能失败。若失败,最多自动请求三次,若仍为失败,则结束。function Random() { return num = parseInt(Math.random()*10);}function Request(count = 1) { let num = Random(); if(num % 2 == 0){ console.log('失败第'+ count + '次'); count++; if(count <= 3){ Request(cou原创 2021-03-19 16:54:00 · 279 阅读 · 0 评论 -
解析字段
/** * @description:解析html */export default { data () { return { //解析后的对象 htmlModel:{} }; }, methods: { /** * @description:解析html * @param data:需要解析的对象 * @param args:指定解析的key */ resolver (data, ...args) { let htmlModel = O原创 2021-03-16 17:13:29 · 127 阅读 · 0 评论 -
Promise
new Promise (function( resolve, reject){ setTimeout(function(){ console.log("first"); resolve(); }, 1000)}).then(function(){ new Promise(function(resolve, reject){ setTimeout(function(){ console.log("second原创 2021-03-12 11:15:20 · 47 阅读 · 0 评论 -
页面滚动到浏览器可视区域动画播放
//可视区域的高window.innerHeight || doucument.documentElement.clientHeight || document.body.clientHeight//整个网页的高(不包括边框) docunment.body.scrollHeight;//整个网页的高(包括边框) docunment.body.offsetHeight;//整个网页的滚动距离document.body.scrollTopdocument.body.scrollleft.原创 2021-03-05 10:41:03 · 463 阅读 · 1 评论 -
数组赋值
引用赋值-浅拷贝let arr1 = [1, 2, 3, 4, 5];let arr2 = arr1;console.log(arr2); //[1, 2, 3, 4, 5]arr1[0] = 22;console.log(arr2); //[22, 2, 3, 4, 5]循环遍历赋值-深拷贝let arr1 = [1, 2, 3, 4, 5];let arr3 = [];for(var i in arr1){ arr3.push(arr1[i]);}console.log原创 2021-02-23 18:37:56 · 66 阅读 · 1 评论 -
提取URL中某一参数name的value
queryString: ?name=value&name1=&name2=value2function getUrlQuery (name) { let reg = new RegExp('(^|&)'+name+'=([^&]*)(&|$)'); let value = window.location.search.subStr(1).match(reg); return value[2]}function getUrlQuery(url, name原创 2021-02-09 14:46:53 · 171 阅读 · 0 评论 -
javascript
Window对象概念:所有全局js对象,全局js函数,全局js变量,document对象都是windows对象成员window.document.getElementById();//等同于document.getElementById();浏览器窗口尺寸大小//window.innerHeight - 浏览器窗口的内高度(以像素计)//window.innerWidth - 浏览器窗口的内宽度(以像素计)//兼容var with = window.innerWidth || docu原创 2021-02-05 11:38:22 · 120 阅读 · 0 评论 -
正则方法
1. reg.test(str)param:待匹配字符串return:true/falseconsole.log(/hello/i.test('HelloWorld'))//trueconsole.log(/hello/.test('HelloWorld'))//false2. reg.exec(str)param:待匹配字符串return:array array[0]表示正则匹配到的字符串var reg = /\d+/g;var str = 'abcdt23tStri12';原创 2021-02-02 14:24:19 · 806 阅读 · 0 评论