vue 输入框输入任意内容返回数字
输入任意内容只返回数字
export function changeEvent(item) {
let nums = item + "";
if (nums === "") {
nums = "";
} else {
nums = nums.replace(/[^\d|\.]/g, "");
if (nums.includes(".")) {
let strL = nums.substring(0, nums.indexOf("."));
let strR = nums.substring(nums.indexOf(".") + 1);
nums = strL + "." + strR;
}
}
return nums;
}
export function blurEvent(x, y) {
if (x === "") {
y.manualScore = "";
} else {
x = x + "";
let nums;
if (x.includes(".")) {
nums = x.replace(/[^\d|\.]/g, "");
let strL = nums.substring(0, nums.indexOf("."));
let strR = nums.substring(nums.indexOf(".") + 1);
strR = strR.replace(/\./gi, "");
if (strL === "" && strR === "") {
nums = "0";
} else if (strL === "" && strR !== "") {
nums = "0." + strR;
} else if (strL !== "" && strR === "") {
nums = strL;
} else if (strL !== "" && strR !== "") {
nums = strL + "." + strR;
}
} else {
nums = x.replace(/[^\d|\.]/g, "");
}
let z = nums * 1 || "";
z = z < 0 ? 0 : z;
y.manualScore = z;
}
console.log("x", x, "y:", y);
}
|