亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字的實(shí)現(xiàn)

 更新時(shí)間:2022年03月30日 15:26:55   作者:前端醬紫  
本文主要介紹了vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

本文主要介紹了vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字,具體如下:

輸入任意內(nèi)容只返回?cái)?shù)字

// 提取數(shù)字 傳入數(shù)字
export function changeEvent(item) {
	let nums = item + "";
	if (nums === "") {
		nums = ""; // 空的話 直接返回空
	} else {
		nums = nums.replace(/[^\d|\.]/g, ""); // 提取出來(lái) 一定是數(shù)字
		if (nums.includes(".")) {
			// 包含小數(shù)點(diǎn)
			let strL = nums.substring(0, nums.indexOf("."));
			let strR = nums.substring(nums.indexOf(".") + 1);
			nums = strL + "." + strR;
		}
		// else {
		// 	// 不包含小數(shù)點(diǎn)
		// 	nums = nums.replace(/[^\d|\.]/g, ""); // 提取出來(lái) 一定是數(shù)字
		// }
	}
	return nums;
}

// 離開輸入事件 
export function blurEvent(x, y) {
	if (x === "") {
		y.manualScore = "";
	} else {
		x = x + "";
		let nums;
		if (x.includes(".")) {
			// 包含小數(shù)點(diǎn)
			nums = x.replace(/[^\d|\.]/g, ""); // 提取出來(lái) 一定是數(shù)字
			let strL = nums.substring(0, nums.indexOf("."));
			let strR = nums.substring(nums.indexOf(".") + 1);
			strR = strR.replace(/\./gi, ""); // 去除多余小數(shù)點(diǎn)
			if (strL === "" && strR === "") {
				nums = "0"; // 有小數(shù)點(diǎn),但左側(cè)右側(cè)都為空 默認(rèn)為0
			} else if (strL === "" && strR !== "") {
				// 左側(cè)為空 右側(cè)不為空 小數(shù)
				nums = "0." + strR;
			} else if (strL !== "" && strR === "") {
				// 右側(cè)為空 左側(cè)不為空 整數(shù)
				nums = strL;
			} else if (strL !== "" && strR !== "") {
				nums = strL + "." + strR;
			}
		} else {
			nums = x.replace(/[^\d|\.]/g, ""); // 提取出來(lái) 一定是數(shù)字
		}
		let z = nums * 1 || "";
		z = z < 0 ? 0 : z;
		y.manualScore = z;
	}
	console.log("x", x, "y:", y);
}

在這里插入圖片描述

 到此這篇關(guān)于vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)vue 輸入框輸入返回?cái)?shù)字內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論