vue 輸入框輸入任意內(nèi)容返回?cái)?shù)字的實(shí)現(xiàn)
本文主要介紹了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)文章
淺談vue項(xiàng)目?jī)?yōu)化之頁(yè)面的按需加載(vue+webpack)
本篇文章主要介紹了vue項(xiàng)目?jī)?yōu)化之頁(yè)面的按需加載(vue+webpack),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-12-12在 Vue3 中如何使用 styled-components
styled-components 的官方 Vue 版本目前已多年沒有更新,而且只支持到 Vue2,那么,在 Vue3 中怎么才能使用到 styled-components 呢,下面給大家介紹在 Vue3 中使用 styled-components的相關(guān)知識(shí),感興趣的朋友跟隨小編一起看看吧2024-05-05在vue.js渲染完界面之后如何再調(diào)用函數(shù)
這篇文章主要介紹了在vue.js渲染完界面之后如何再調(diào)用函數(shù)的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07Vue3+Vant實(shí)現(xiàn)簡(jiǎn)單的登錄功能
這篇文章主要為大家詳細(xì)介紹了Vue3如何結(jié)合Vant實(shí)現(xiàn)簡(jiǎn)單的登錄功能,文中的示例代碼講解詳細(xì),有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-04-04Vue 權(quán)限控制的兩種方法(路由驗(yàn)證)
這篇文章主要介紹了Vue 權(quán)限控制的兩種方法(路由驗(yàn)證),每種方法給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08vue-axios同時(shí)請(qǐng)求多個(gè)接口 等所有接口全部加載完成再處理操作
這篇文章主要介紹了vue-axios同時(shí)請(qǐng)求多個(gè)接口 等所有接口全部加載完成再處理操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-11-11