随笔分类 -  JavaScript

摘要:console.time('starttime'); //将请求添加到promise内 let p1 = new Promise((resolve, reject) => { axios({ url: url method: 'post', data: { } }) .then((res) => { 阅读全文
posted @ 2022-01-22 10:49 ComeIntoBud 阅读(143) 评论(0) 推荐(0) 编辑
摘要:1 //验证手机号码 2 checkPhone(phone) { 3 if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone))){ 4 return false; //不满足条件 5 }else{ 6 return true ;//满足条件 7 } 8 }, 阅读全文
posted @ 2022-01-20 17:20 ComeIntoBud 阅读(359) 评论(0) 推荐(0) 编辑
摘要:1 var now = new Date(); // 当前日期 2 var nowDayOfWeek = now.getDay(); // 今天本周的第几天 3 var nowDay = now.getDate(); // 当前日 4 var nowMonth = now.getMonth(); / 阅读全文
posted @ 2022-01-20 16:50 ComeIntoBud 阅读(716) 评论(0) 推荐(0) 编辑
摘要:0.给身份证加* 号 let idNo = '5123456789789789789' //身份证号码 let manySpace=function(num,space){ //生成指定字符和个数的字符串 let str = '' for(let i=0;i<num;i++){ str+=space 阅读全文
posted @ 2021-09-15 15:18 ComeIntoBud 阅读(64) 评论(0) 推荐(0) 编辑
该文被密码保护。
posted @ 2021-09-06 09:06 ComeIntoBud 阅读(0) 评论(0) 推荐(0) 编辑
摘要:http://momentjs.cn/ 官网很详细 阅读全文
posted @ 2021-09-02 09:44 ComeIntoBud 阅读(76) 评论(0) 推荐(0) 编辑
摘要:话不多说 直接上代码 changeTime(){ let nowTime = new Date() let year = nowTime.getFullYear() let month = nowTime.getMonth()+1 if((month+'').length==1){ month = 阅读全文
posted @ 2021-07-29 17:49 ComeIntoBud 阅读(49) 评论(0) 推荐(0) 编辑
摘要:在日常开发中经常遇到类似情况: 后端返回一个list,含有时间,前端要展示最新时间的那一条,后端又没有做排序,so此需要用Js相关内容进行对数组进行排序。 如我们拿到类似以下的list: const list = [ { title: '第一条消息', createTime: "2020-04-01 阅读全文
posted @ 2021-07-12 16:39 ComeIntoBud 阅读(356) 评论(0) 推荐(0) 编辑
摘要:// 星号处理手机号 noPassByMobile(str){ if(null != str && str != undefined){ var pat=/(\d{3})\d*(\d{4})/; return str.replace(pat,'$1****$2'); } else { return 阅读全文
posted @ 2021-07-10 17:43 ComeIntoBud 阅读(118) 评论(0) 推荐(0) 编辑
摘要:1.使用isNaN()函数 isNaN()的缺点就在于 null、空格以及空串会被按照0来处理 NaN: Not a Number /***判断是否是数字***/ function isRealNum(val){ // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除 // 阅读全文
posted @ 2021-07-08 13:42 ComeIntoBud 阅读(254) 评论(0) 推荐(0) 编辑
摘要:方法1:通过eval var a = 5; for (var i = 1; i <= a; i++) { eval("var a" + i + "=" + i); } alert(a1); 注意 必须是 var 声明 let 和 const 会报错 方法2: 连续声明 var a,b,c,d,e,f 阅读全文
posted @ 2021-07-01 13:37 ComeIntoBud 阅读(216) 评论(0) 推荐(0) 编辑
摘要:String对象的方法 方法一: indexOf() (推荐) var str = "123"; console.log(str.indexOf("3") != -1 ); // true indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。如果要检索的字符串值没有出现,则该方 阅读全文
posted @ 2021-06-19 18:14 ComeIntoBud 阅读(75) 评论(0) 推荐(0) 编辑
摘要:像这种代码就很打脑壳~ // 贷款申请操作的处理 function check() { // 是否输入正确用户名 if (this.checkUsername(this.username)) { // 是否输入正确身份证号 if (this.checkIdCard(this.idCard)) { / 阅读全文
posted @ 2021-06-05 13:49 ComeIntoBud 阅读(2212) 评论(0) 推荐(0) 编辑
摘要:var date1= '2019-04-26 11:05:32'; //开始时间 var date2 = new Date(); //结束时间 var date3 = date2.getTime() - new Date(date1).getTime(); //时间差的毫秒数 var subMinu 阅读全文
posted @ 2021-06-03 15:52 ComeIntoBud 阅读(2041) 评论(0) 推荐(1) 编辑
摘要:总结: 1. 只要验证字符串格式或查找、屏蔽敏感词时都要用正则 (1). 最简单的正则: 一个敏感词的原文 (2). 某一位字符上可能有多种备选字时用: [备选字列表] (3). 如果[]中部分字符是连续的,可用: [x-x] a. 一位小写字母: [a-z] b. 一位大写字母: [A-Z] c. 阅读全文
posted @ 2021-02-26 08:47 ComeIntoBud 阅读(141) 评论(0) 推荐(0) 编辑
摘要:ES6 一. 模板字符串 (1). 问题: 旧js中,拼接字符串,只能用+,但是+极容易和算术计算的+冲突! (2). 解决: 只要动态拼接字符串,都可用模板字符串 (3). 什么是: 支持动态拼接内容,支持换行的特殊的字符串。 (4). 如何: 3句话: a. 整个字符串要用一对儿反引号` `(键 阅读全文
posted @ 2021-02-16 23:52 ComeIntoBud 阅读(120) 评论(0) 推荐(0) 编辑
摘要:ES5: ECMAScript标准的第五个版本 严格模式 什么是: 比旧的js运行机制要求更严格的运行机制。 为什么: 因为旧的js运行机制有很多广受诟病的缺陷! 何时:项目中,都要在严格模式下开发! 如何启用严格模式:只要在当前作用域的顶部添加"use strict";,那么,当前作用域内的程序, 阅读全文
posted @ 2021-02-05 20:45 ComeIntoBud 阅读(98) 评论(0) 推荐(0) 编辑
摘要:函数:程序中保存一段可反复使用的代码片段的程序结构 应用地方:只要一段代码可能被多次反复使用,都要先封装在一个函数中,再调用函数,执行任务 . 如果函数内部必须某些数据才能正常执行时,必须定义形参! . 如果函数外部的后续程序想继续使用函数的执行结果时,必须定义返回值return。 重载:一件事,根 阅读全文
posted @ 2021-02-05 19:45 ComeIntoBud 阅读(81) 评论(0) 推荐(0) 编辑
摘要:一在介绍ajax请求之前先介绍一点DOM的简易操作 由于在html5中用form标签发送请求时,form表单有自动收集整理数据的功能(通过name属性) 使用ajax,就不用form表单了,所以就失去了自动收集整理数据的能力(即不用name) 我们需要手动写代码收集数据 dom操作 我们知道java 阅读全文
posted @ 2021-01-06 23:51 ComeIntoBud 阅读(441) 评论(0) 推荐(0) 编辑
摘要:一.首先介绍下HTTP协议中的URL URL 的结构:协议+主机名称+目录结构+文件名称 URL完整的结构: <scheme>://<user>:<upwd>@<host>:<port>/<path>;<params>?<query>#<flag> 接下来就一一介绍其中的每一个元素的意义 ①<sch 阅读全文
posted @ 2021-01-04 23:32 ComeIntoBud 阅读(99) 评论(0) 推荐(0) 编辑

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