随笔分类 -  js知识总结

摘要:一、关于取值 const {a,b,c,d,e} = obj; const f = a + d; const g = c + e; 注:ES6的解构赋值虽然好用。但是要注意解构的对象不能为undefined、null。否则会报错,故要给被解构的对象一个默认值。 const {a,b,c,d,e} = 阅读全文
posted @ 2022-07-11 16:43 dongxiaolei 编辑
摘要:1. Array.push(),向数组的末尾添加一个或多个元素,并返回新的数组长度。原数组改变。 2. Array.pop(),删除并返回数组的最后一个元素,若该数组为空,则返回undefined。原数组改变。 3. Array.unshift(),向数组的开头添加一个或多个元素,并返回新的数组长度 阅读全文
posted @ 2021-02-19 11:06 dongxiaolei 编辑
摘要://判断某个数组中是否包含另一个数组 function isContained (a, b){ if(!(a instanceof Array) || !(b instanceof Array)) return false; if(a.length < b.length) return false; 阅读全文
posted @ 2021-02-05 14:53 dongxiaolei 编辑
摘要:limitDecimals = value => { const reg = /^(\-)*(\d+)\.(\d).*$/; if (typeof value 'string') { return !isNaN(Number(value)) ? value.replace(reg, '$1$2.$3 阅读全文
posted @ 2021-02-04 17:00 dongxiaolei 编辑
摘要:原生js判断有没有class hasClass = (ele, cName) => { let reg = new RegExp("(?:^| +)" + cName + "(?: +|$)", "g"); if(ele.className undefined){ return false; }el 阅读全文
posted @ 2021-02-04 16:38 dongxiaolei 编辑
摘要:跨域解决方案1)jsonp,通过动态创建script标签,将请求url赋值给script的src属性,并在src属性后边拼接需要传的值,通过get方式传给后端,2)cors方式:后端通过修改请求头,允许跨域3)反向代理,后端在服务器上配置代理jsonp只能get请求// 1.创建一个全局函数 fun 阅读全文
posted @ 2020-11-01 20:35 dongxiaolei 编辑
摘要:1) Date.parse(new Date()) 2)new Date().getTime() 3)new Date().valueOf() 4)Date.now() 阅读全文
posted @ 2020-10-22 20:20 dongxiaolei 编辑
摘要://Promise执行 执行resolve会进then 执行reject会进入catchsetTimeout(()=>{ console.log('set1'); }) new Promise((resolve,reject)=>{ console.log('p1'); resolve(); //同 阅读全文
posted @ 2020-05-21 14:20 dongxiaolei 编辑
摘要:数组排序 //方法1 // 数组中前一项跟后一项作比较,如果前边的比后边的大,则前后换一下位置 function px1(ary){ var len=ary.length,temp; if(len<=1){ return ary; } for(var i=0;i<len;i++){ for(var 阅读全文
posted @ 2018-03-09 11:25 dongxiaolei 编辑
摘要:JS数组去重的几种常见方法 一、简单的去重方法 // 最简单数组去重法 /* * 新建一新数组,遍历传入数组,值不在新数组就push进该新数组中 * IE8以下不支持数组的indexOf方法 * */ function uniq(array){ var temp = []; //一个新的临时数组 f 阅读全文
posted @ 2018-03-09 09:34 dongxiaolei 编辑
摘要:var num=1; $(document).on("mousewheel DOMMouseScroll", function (e) { var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) || // chrome & ie ... 阅读全文
posted @ 2017-12-20 14:30 dongxiaolei 编辑
摘要:Math.pow(x,y) //x的y次幂(方) 一、常用方法单词: 数学方法 DOM属性和方法 数组: 思考题: 阅读全文
posted @ 2017-12-07 10:22 dongxiaolei 编辑
摘要:$("link,script").each(function(){ var t=Math.random().toFixed(4); /*var $tag=$(this).prop("tagName").toLowerCase();//获取当前元素的标签名 if($tag == "link"){ var $href=$... 阅读全文
posted @ 2017-02-07 16:35 dongxiaolei 编辑
摘要:http://www.cnblogs.com/aliyue/p/5610850.html http://www.cnblogs.com/jscode/archive/2012/07/10/2583856.html http://www.cnblogs.com/yexiaochai/p/3152858 阅读全文
posted @ 2017-02-05 15:05 dongxiaolei 编辑
摘要:function goPAGE() { if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Win... 阅读全文
posted @ 2017-01-21 11:11 dongxiaolei 编辑
摘要:function add(a,b) { alert(a+b); } function sub(a,b) { alert(a-b); } add.call(sub,3,1); 例子1中的意思就是用 add 来替换 sub,add.call(sub,3,1) == add(3,1) ,所以运行结果为:a 阅读全文
posted @ 2017-01-19 17:03 dongxiaolei 编辑
摘要:function fun_date(aa){ var date1 = new Date(), time1=date1.getFullYear()+"-"+(date1.getMonth()+1)+"-"+date1.getDate();//time1表示当前时间 var date2 = new Date(date1); date2.... 阅读全文
posted @ 2017-01-16 14:13 dongxiaolei 编辑

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