js各种集锦

1.判断是否为数字

function isNumber(value) {
  return /^-?\d+(\.\d+)?$/.test(value);
}

2.截取长字符换行提示

function getHHContent(content,lengs) {
    var str = "";
    if (content != "" && content != null && content != undefined) {
        var index = 0;
        while (index < content.length) {
            var spstr = content.slice(index, index += lengs);
            if (spstr!="") {
                str += "<p>"+spstr+"</p>";
            }
        }
    }
    return str;
}

3.判断是否含有空格

function hasSpace(str) {
    var pattern = /\s/; // 定义正则表达式 \s 匹配任意空白字符(包括空格、制表符等)
    return pattern.test(str); // test() 方法返回 true 或 false,根据字符串 str 是否包含空格进行判断
}

4.替换字符串中的所有指定字符

function replaceAll(str, find, replace) {
  return str.replace(new RegExp(find, 'g'), replace);
}

5.计算小数(处理精度问题)

//添加金额
function addNum(num1, num2) {
    num1 == undefined ? num1 = 0 : ''
    num2 == undefined ? num2 = 0 : ''
    var sq1, sq2, m;
    try {
        sq1 = num1.toString().split(".")[1].length;
    }
    catch (e) {
        sq1 = 0;
    }
    try {
        sq2 = num2.toString().split(".")[1].length;
    }
    catch (e) {
        sq2 = 0;
    }
    m = Math.pow(10, Math.max(sq1, sq2));
    return (num1 * m + num2 * m) / m;
}

6.查找字符出现的所有索引位置

//字符出现的所有位置
function getAllIndexes(str, charToFind) {
  const indexes = [];
  let index = str.indexOf(charToFind);
  while (index > -1) {
    indexes.push(index);
    index = str.indexOf(charToFind, index + 1);
  }
  return indexes;
}

vue3.0 elementui 栅格5等分

  <ElCol :span="5">
  @media screen and (min-width: 769px){
    .el-col-5 {
      max-width: 20%;
      width: 20%;
      flex: 0 0 20%;
    }
  }
  @media screen and (min-width: 569px) and (max-width: 768px) {
    .el-col-5 {
      max-width: 50%;
      width: 50%;
      flex: 0 0 50%;
    }
  }
  @media only screen and (max-width: 568px){
    .el-col-5 {
      max-width: 100%;
      width: 100%;
      flex: 0 0 100%;
    }
  }
  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值