
js
js笔记
江禾
我是一个小菜鸡,又菜又辣鸡。
展开
-
echarts的x轴不带时分秒,tooltip带时分秒
//x轴xAxis: { name: "时间", type: "category", boundaryGap: false, data: this.reserve(this.tData).map((item) => item.collectTime), axisLine: { lineStyle: { color: "#03c5fd", }, }, axisLabel: { formatter: (name) => n原创 2022-01-21 14:10:10 · 1289 阅读 · 0 评论 -
数组对象去重
数组对象去重let targetNode=[{id:"1",text:"芋圆"},{id:"2",text:"啵啵"},{id:"1",text:"芋圆"},]let obj = {}; let newTarget = targetNode.reduce((cur, next) => { obj[next.id] ? "" : obj[next.id] = true && cur.push(next); return cur; }, [])原创 2021-11-01 15:10:34 · 117 阅读 · 0 评论 -
js实现鼠标滚轮图片放大缩小
<!doctype html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Document</title></head><body> <img id="img" src="11.png" alt="" style="width:100p原创 2020-09-16 16:06:42 · 6436 阅读 · 0 评论 -
js实现放大镜的效果
基本布局<div id="box"> <div id="middleImg"> <img src="images/images2/1_2.jpeg" /> <div id="middleArea"></div> </div> <div id="small"> <ul> <li><img src="i原创 2020-08-17 22:00:02 · 185 阅读 · 0 评论 -
冒泡排序,选择排序,快速排序三种排序方式
(1)冒泡排序for (i = 0; i < arr.length - 1; i++) { for (j = 0; j < arr.length - i - 1; j++) { if (arr[j] > arr[j + 1]) { var tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; } }}(2)选择排序for (i = 0; i < arr.lengt原创 2020-08-17 21:51:14 · 257 阅读 · 0 评论 -
实现继承的几种方式
(1)寄生继承Object.create(2)构造函数+对象冒充 function Person(_name, _age) { this.name = _name; this.age = _name } Person.prototype.fly = function () { console.log("fly") } function Student(_name, _age, _job) { Person.call(t原创 2020-08-17 21:48:43 · 114 阅读 · 0 评论 -
promise相关
回调地狱需求是: 通过选择省,再去发请求,选择城市,再发请求,请求到区$.ajax({ //全国有多少省 type:'get/post' url:'www', dataType:'json/jsonp' async:true, data:{ id:"1" }, success:function(res){ console.log(res) $.ajax({ //这个省有多少市原创 2020-08-17 21:42:00 · 136 阅读 · 0 评论 -
js的继承
(1)寄生继承Object.create(2)构造函数+对象冒充function Person(_name, _age) { this.name = _name; this.age = _name}Person.prototype.fly = function () { console.log("fly")}function Student(_name, _age, _job) { Person.call(this, _name, _age) this.job = _jo原创 2020-07-20 22:15:45 · 109 阅读 · 0 评论 -
数组扁平化(多维变一维)
(1)es6的拓展运算符var arr = [[1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14]]]], 10];function flatten(arr) { while (arr.some(item => Array.isArray(item))) { arr = [].concat(...arr); } return arr;}console.log(flatten(arr))(2)递归var原创 2020-07-20 22:12:20 · 167 阅读 · 0 评论 -
数组去重的方法
(1)es6的拓展运算符和Setconsole.log(…new Set(arr))(2)遍历function unique (arr) {let newarr = []for (let i = 0; i < arr.length; i++) {if (newarr .indexOf(arr[i]) === -1) {newarr .push(arr[i])}}return newarr}console.log(unique (arr) )...原创 2020-07-20 22:09:56 · 87 阅读 · 0 评论 -
新增数组对象方法
1 isArray()Array.isArray()方法是用来判断某个值是否是数组,如果是,则返回true,否则返回false,用于判断一些类似数组的对象很有用。因为无论是数组还是对象,对于typeof的操作返回值都为object,所以就有了区分数组类型和对象类型的需要.而有些对象中又存在length属性,instanceof用来判断内存中实际对象A是不是B类型2 indexOf(),lastIndexOf() [ES5]indexOf()方法返回给定元素能找在数组中找到的第一个索引值,否则则返回原创 2020-07-09 21:49:47 · 2017 阅读 · 0 评论 -
新增的字符串方法
字符串includes():返回布尔值,表示是否找到了参数字符串。startsWith():返回布尔值,表示参数字符串是否在源字符串的头部。endsWith():返回布尔值,表示参数字符串是否在源字符串的尾部。repeat(): 返回一个新字符串,表示将原字符串重复n次.1 trim()清除空白 [Es6]2 for of 循环字符串var str = "????";for(var i=0; i<str.length; i++) { console.log(str[i]);原创 2020-07-09 21:39:43 · 181 阅读 · 0 评论 -
map里面不能return
用map进行遍历,在里面进行判断的时候,return不能起到相关作用.可以把map改为for循环,然后再进行return原创 2020-07-06 21:17:31 · 5833 阅读 · 1 评论 -
日期相关表达
获取当前日期var date=new Date(); 这个页面在运行的那一刻,获取本地计算机时间console.log(date.getFullYear()); 获取当前年console.log(date.getMonth()); 获取月份console.log(date.getDay()); 获取星期几console.log(date.getDate()); 获取日console.log(date.getHours()); 获取小时,24进制console.log(date.getMinut原创 2020-06-11 22:49:12 · 242 阅读 · 0 评论 -
offset系列知识和事件对象
offsetParent 找带有定位的父元素,如果父级们,都没有定位,找bodyoffsetLeft 和offsetTop 到带有定位的父元素的距离,如果父级们, 都没有定位,到body的距离offsetWidth和offsetHeight 得到自身的大小 padding+border+自身的宽高=自身大小事件对象console.log(e.pageY) 鼠标点击的点,到页面不可见区域的高度console.log(e.clientY) 鼠标点击的点,到可视区域的距离console原创 2020-06-09 21:24:58 · 282 阅读 · 0 评论 -
js实现浏览器宽度改变,样式随之变化
响应式做法,浏览器宽度//document.documentElement.clientWidth 浏览器的宽度 window.onresize = function () { //document.documentElement.clientWidth 浏览器的宽度 if (document.documentElement.clientWidth > 200 && document.documentElement.clientW原创 2020-06-08 22:39:14 · 1560 阅读 · 0 评论 -
ajax的get请求与post请求
Ajax 技术核心是JavaScript对象XMLHttpRequest(简称 XHR), 它是一种支持异步请求数据的技术.与服务器进行数据交换,实现同步或异步的刷新.ajax.post.jsconst Ajax = (function () { // {uname:123,upwd:123}; // uname=123&upwd=123& function getPrams(obj) { var str = ""; for (v原创 2020-06-04 21:49:35 · 155 阅读 · 0 评论 -
正则表达式
var reg = new RegExp("box");var str = "this is a Box box ";console.log(reg.test(str));var reg = /box/; var str = "this is a Box box "; console.log(reg.test(str));1, test() : 返回true则符合, false则不符合2, exec() : 返回数组则符合, null则不符合这两种方法使用正则表达式对象去调用, 参数为要原创 2020-06-03 19:39:15 · 87 阅读 · 0 评论 -
鼠标事件,键盘事件,html事件
鼠标事件1.click: 当单击鼠标按钮并在松开时触发onclick = function() { console.log('单击了鼠标'); };2.dblclick: 当双击鼠标按钮时触发。ondblclick = function() { console.log('双击了鼠标'); };3.mousedown:当按下了鼠标还未松开时触发。onmousedown = function() { console.log('按下鼠标');原创 2020-06-03 19:24:28 · 245 阅读 · 0 评论 -
Math的用法
Math.round(3.6) //四舍五入 Math.random() //返回0-1之间的随机数 [0,1) Math.max(num1, num2) //返回较大的数 Math.min(num1, num2) //返回较小的数 Math.abs(num) //绝对值 Math.ceil(19.3) //向上取整 -2.9 -2 2.1 3 Math.floor(11.8) //向下取整 -2.9 -3 2...原创 2020-06-01 15:49:41 · 1411 阅读 · 0 评论 -
ES3数组和字符串的方法
数组的方法1.push arr.push()往数组的最后一个位置添加一个新的元素,并返回该数组的新长度2.pop arr.pop()删除数组最后一位元素,并返回被删除的那个元素3.shift arr.shift()删除数组第一位元素,并返回被删除的那个元素4.unshift()往数组的第一个位置添加一个新的元素,并返回新数组的新长度5.reverse()反序,返回被修改之后的数组6.sort()默认从小到大排序(比较个位数的大小,比较ASCII码,127字符串)ASCI原创 2020-06-01 15:47:41 · 379 阅读 · 0 评论 -
parseInt和parseFloat
parseInt() 是把其它类型转换为整型var str="100px";console.log( parseInt(str) ) //100parseFloat() 是把其它类型转换为浮点型(小数)var str1="1.3亿";console.log( parseFloat(str1) ) //1.3其他进制转10进制// parseIntvar s=10101000; //2进制var num=parseInt(s,2)console.log(num);原创 2020-06-01 15:38:42 · 307 阅读 · 0 评论