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 % ;
}
}