随笔分类 -  JavaScript

javascript
摘要:// 获取下个月的特定一天 getSpecificDayOfNextMonth(day, dayEnd = 0) { let now = new Date(); now.setMonth(now.getMonth() + 1, day); // 设置月份加一,日期设置为特定的一天 if (dayEn 阅读全文
posted @ 2024-12-07 16:33 烧机 阅读(18) 评论(0) 推荐(0) 编辑
摘要:js树型结构数据简易递归 // item内的值根据实际情况更换replaceValueInTree (tree) { const result = [] tree.forEach((item) => { let children = item.children || [] if (Array.isA 阅读全文
posted @ 2024-10-17 17:19 烧机 阅读(37) 评论(0) 推荐(0) 编辑
摘要:// 去除字符串两边的指定字符function strTrim(string, char, type) { if (char) { if (type 'left') { return string.replace(new RegExp('^\\' + char + '+', 'g'), ''); } 阅读全文
posted @ 2024-07-23 14:52 烧机 阅读(9) 评论(0) 推荐(0) 编辑
摘要:js substr 根据字节长度截取字符串此方法应该还可以被优化一下 /** * 根据字节长度截取字符串 * @param str 字符串 * @param bytesStart 字节截取起始位置 * @param bytesLen 字节截取长度 */substrByBytes(str, bytes 阅读全文
posted @ 2024-03-21 13:49 烧机 阅读(112) 评论(0) 推荐(0) 编辑
摘要:方法1:把input的 type="password" 改成 type="text" 并在后面加上 οnfοcus="this.type='password'" <input type="text" placeholder="密码" onfocus="this.type='password'"/> 阅读全文
posted @ 2024-02-23 15:34 烧机 阅读(654) 评论(0) 推荐(0) 编辑
摘要:a:要追加的位置 b:要追加的内容 1、append:a.append(b) 将b追加到a的内部的末尾,b是a的子元素 2、appendTo:b.appendTo(a) 将b追加到a的内部的末尾,b是a的子元素 3、prepend:a.prepend(b),将b追加到a的内部的最前面,b是a的子元素 阅读全文
posted @ 2024-02-20 11:18 烧机 阅读(924) 评论(0) 推荐(0) 编辑
摘要:有时为了格式美观,我们需要给数字统一格式,比如001,002,003,这就有了为数字补足0的需求。具体见代码 // num: 数字 // fill: 补足后的位数 padNumber(num, fill) { let len = ('' + num).length; if (fill > len) 阅读全文
posted @ 2024-01-22 16:27 烧机 阅读(912) 评论(0) 推荐(1) 编辑
摘要:移动端H5页面加上 <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"> 还是会被浏览器强制缩放。 阅读全文
posted @ 2023-12-21 16:04 烧机 阅读(203) 评论(0) 推荐(0) 编辑
摘要:const isJson = str => { try { JSON.parse(str); return true; } catch (e) { return false; } }; isJson('{"name":"小明","address":"苏州"}'); // true isJson('{ 阅读全文
posted @ 2023-11-25 08:28 烧机 阅读(69) 评论(0) 推荐(0) 编辑
摘要:vue3配置跳转到新的路由界面的位置 import { createRouter, createWebHashHistory } from 'vue-router' // vue2.0 new VueRouter({}) 创建路由实例 // vue3.0 creatRouter({}) 创建路由实例 阅读全文
posted @ 2022-06-10 22:52 烧机 阅读(523) 评论(0) 推荐(0) 编辑
摘要:一,async函数介绍 1.async函数是异步的一种方案,可以让异步的操作同步执行。 二,async函数基本形式 1.声明形式:在函数前加上关键字async 表示该函数是一个async 函数 async function fn(){ await ... } const fn = async ()= 阅读全文
posted @ 2022-05-28 09:01 烧机 阅读(253) 评论(0) 推荐(0) 编辑
摘要:封装axios一、创建文件utils/request.js // 基于 axios 封装的请求模块 import axios from 'axios' // 新建一个新的axios实例 const newAxios = axios.create({//创建返回一个新的axios函数对象 baseUR 阅读全文
posted @ 2022-05-26 11:03 烧机 阅读(98) 评论(0) 推荐(0) 编辑
摘要:JS 键盘 阅读全文
posted @ 2018-10-23 11:16 烧机 阅读(16449) 评论(0) 推荐(0) 编辑
摘要:1. var patrn = /^\d+(\.\d+)?$/; var num = 0.11; if (!patrn.exec(num)){ alert("请您输入数字");return; }2. var patten = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g; var 阅读全文
posted @ 2018-09-29 16:31 烧机 阅读(29175) 评论(0) 推荐(1) 编辑

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