摘要: function getWord(name) { var wd = JSON.parse("{\"" + decodeURI(window.location.search).replace(/\?/, "").replace(/=/g,"\":\"").replace(/&/g,"\",\"") + 阅读全文
posted @ 2021-09-22 18:21 李健威 阅读(287) 评论(0) 推荐(0)
摘要: // 以前每次要实现发送验证码倒计时或者时分秒倒计时都要自己重新写一遍,为了方便日后不用每次都写一大堆方法和变量,特意写了这一篇文章,供以后使用。 // 定义一个类以及调用类的静态方法的方式实现倒计时,可改变类的静态属性关闭倒计时 class timer { // 倒计时 static countD 阅读全文
posted @ 2021-09-15 15:34 李健威 阅读(354) 评论(0) 推荐(0)
摘要: <input class="number-input" type="text" v-model="number" placeholder="0.00" @input="numberFixedDigit" /> numberFixedDigit (e) { // 固定两位小数 e.target.val 阅读全文
posted @ 2021-09-14 15:26 李健威 阅读(3723) 评论(0) 推荐(1)
摘要: 小数计算过程中精度缺失的,最经典的是0.1+0.2 = 0.30000000000000004,原因是因为数值的表示在计算机内部是用二进制的, 那么出现这种情况的时候我们如何避免计算结果达到我们要的0.3呢?其实我们只要把计算得到的结果固定10位,然后再转换为浮点数就可以了。 function ca 阅读全文
posted @ 2021-09-14 14:22 李健威 阅读(313) 评论(0) 推荐(0)
摘要: // js强制固定多少位小数,是否四舍五入取决于round参数,默认四舍五入 function fixedDigit (vlue, digit=2, round=true) { if (round) { // 四舍五入 return (Math.round(parseFloat(vlue)*Math 阅读全文
posted @ 2021-09-14 13:54 李健威 阅读(83) 评论(0) 推荐(0)
摘要: // 参数解释: date是时间,默认当前时间 fmt是格式化方式 date参数举例: 1、new Date() fmt参数类型举例: 1、YYYY.MM.DD hh:mm:ss 2、YYYY/MM/DD hh:mm:ss 3、YYYY/MM/DD 4、hh:mm:ss 5、YYYY年MM月DD日 阅读全文
posted @ 2021-09-14 13:26 李健威 阅读(249) 评论(0) 推荐(0)
摘要: 正则表达式替换法一: var str = "123456789" str.replace(/\B(?=(?:\d{3})+\b)/g, ',') // 匹配单词边界替换为逗号 正则表达式替换法二: var str = "123456789" str.replace(/(\d)(?=(\d{3})+$ 阅读全文
posted @ 2021-09-14 13:02 李健威 阅读(715) 评论(0) 推荐(0)
摘要: 正则表达式替换法: var str = "123456789" function reverseStr(str) { return str.replace(/./g, (char, index) => { return str[str.length - index - 1] }) } reverse 阅读全文
posted @ 2021-09-14 12:21 李健威 阅读(682) 评论(0) 推荐(0)