vue移動(dòng)端實(shí)現(xiàn)ip輸入框問(wèn)題怎么解決?這個(gè)問(wèn)題可能是我們?nèi)粘W(xué)習(xí)或工作經(jīng)常見(jiàn)到的。希望通過(guò)這個(gè)問(wèn)題能讓你收獲頗深。下面是小編給大家?guī)?lái)的參考內(nèi)容,讓我們一起來(lái)看看吧!
創(chuàng)新互聯(lián)建站于2013年創(chuàng)立,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元正鑲白做網(wǎng)站,已為上家服務(wù),為正鑲白各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792vue框架移動(dòng)端做ip輸入框組件,input在瀏覽器和微信端兼容問(wèn)題。
要求:只能輸入數(shù)字,輸入數(shù)字以外的字符(包括點(diǎn)、冒號(hào)等數(shù)字符號(hào))時(shí)自動(dòng)跳到下一段ip輸入框.
type=number類(lèi)型,不會(huì)禁止點(diǎn)的輸入。手動(dòng)過(guò)濾拿不到包括點(diǎn)字符的字符串.而且輸入多個(gè)點(diǎn)之后,拿到的值為空.
解決辦法:type=tel,只能輸入數(shù)字,且可以獲取到點(diǎn)字符的輸入
問(wèn)題:微信下keyup事件無(wú)效,回調(diào)事件中event.keyCode返回全是229.
解決辦法:監(jiān)聽(tīng)input事件,event事件對(duì)象中keycode為空,但是event.data返回輸入字符,可以實(shí)現(xiàn)過(guò)濾.
<template> <div> <ul :class="{isDisabled:isDisabled}" > <li :key='index' v-for="(item,index) in ipAdress"> <input :tabindex="'ipInput'+(index+1)" :class="'ipAdress'+(index+1)" @blur="blurFocus(index)" autocomplete="off" :readonly="isDisabled" maxlength="3" type="tel" pattern="[0-9]{1,3}" @input="checkIpVal(item,index,$event)" :disabled="isDisabled" @keyup="turnIpPOS(item,index,$event)" @keydown="delteIP(item,index,$event)" v-model="item.value" ref="ipInput" /> <span v-if="index<3">.</span> </li> </ul> </div> </template> <script> export default { data() { return { ipAdress: [{ value: '' }, { value: '' }, { value: '' }, { value: '' }], isWX:navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger" }; }, props: { ipStr: { trype: String, default: '' }, ipType: { type: String }, isDisabled: { type: Boolean, default: false }, width: { type: String, default:'100%' } }, watch: { ipStr:{ immediate:true, handler:function(vall) { let val = vall; let nArr = []; if(val && val.includes('.') && val.length > 0) { let valArr = val.split('.'); let m = valArr.length; for(let i = 0; i < 4; i++) { if(valArr[i] == 'null' || valArr[i] == 'undefined'){ valArr[i] = ''; } if(i < m) { nArr.push({ value: valArr[i] }); } else { nArr.push({ value: '' }); } } } else { nArr = [{ value: '' }, { value: '' }, { value: '' }, { value: '' }]; } this.ipAdress = nArr; } } }, methods: { //methods blurFocus(index) { if(index == 3) { this.$emit('blur'); } }, checkIpVal(item,index,event) { let self = this; //wx if(this.isWX){ let e = event || window.event; let keyCode = e.data; // //.向右跳轉(zhuǎn) if(keyCode === ".") { e.preventDefault(); e.returnValue = false; item.value = item.value.replace(/[^\d]/g, "").replace(/[\.]/g, ""); if(index < 3 ) { self.$refs.ipInput[index + 1].focus(); } return false; } } let isNo = /^[0-9]{1,3}$/g; if(/[^\d]/g.test(item.value)){ let cache = JSON.parse(JSON.stringify(self.ipAdress)); cache[index].value = item.value.replace(/[^\d]/g, "").replace(/[\.]/g, ""); self.ipAdress = cache; return false; } if(item.value.replace(/[^\d]/g, "").length >= 3) { let val = parseInt(item.value.replace(/[^\d]/g, ""), 10); if(isNaN(val)) { val = '' } else if(val > 255) { val = 255; } else { val = val < 0 ? 0 : val; } item.value = String(val); this.$set(this.ipAdress,index,item); if(index < 3 ) { self.$refs.ipInput[index + 1].focus(); } } let ns = ''; this.ipAdress.forEach(item => ns += '.' + item.value); if(ns.length <= 4){ this.$emit('getIP', "", this.ipType); }else{ this.$emit('getIP', ns.slice(1), this.ipType); } }, turnIpPOS(item, index, event) { let self = this; let e = event || window.event; if(e.keyCode == 37) { if(index != 0) { self.$refs.ipInput[index - 1].focus(); } } //右箭頭、回車(chē)鍵、空格鍵、冒號(hào)均向右跳轉(zhuǎn),右一不做任何措施 if(e.keyCode == 39 || e.keyCode == 13 || e.keyCode == 32 || e.keyCode == 110 || e.keyCode == 46 || e.keyCode == 190 ) { e.preventDefault(); e.returnValue = false; if(index < 3 ) { self.$refs.ipInput[index + 1].focus(); } return false; } }, delteIP(item, index, event) { let self = this; let e = event || window.event; let val = parseInt(item.value.replace(/[^\d]/g, ""), 10); val = isNaN(val) ? '' : val; if(e.keyCode == 8 && index > 0 && val.length==0) { self.$refs.ipInput[index - 1].focus(); } } }, mounted(){ console.log(this.$props) console.log(this.$attrs.index) } }; </script> <style scoped> $--border-color:#ccc; $--outline-color:transparent; $--font-color:$--input-color; $base-font-size:12px; .ipInput { box-sizing: border-box; line-height: inherit; border: 1px solid $--border-color; overflow: hidden; border-radius: 5px; padding: 0; margin: 0; display: inline-block; vertical-align: middle; outline: $--outline-color; font-size:0; text-indent: 0; background: #fff; &.isDisabled { background: $--outline-color; li{ cursor:not-allowed; input{ cursor:not-allowed; } } } li { display: inline-block; width:25%; box-sizing: border-box; font-size:0; input { appearance: none; padding:10px 5px; width: calc(100% - 3px); text-align: center; outline: none; border: none; color: $--font-color; box-sizing: border-box; font-size: $base-font-size; &:disabled { background: $--outline-color; } } span { display: inline-block; font-size:$base-font-size; width: 3px; color: $--font-color; } } } </style>
感謝各位的閱讀!看完上述內(nèi)容,你們對(duì)vue移動(dòng)端實(shí)現(xiàn)ip輸入框問(wèn)題怎么解決大概了解了嗎?希望文章內(nèi)容對(duì)大家有所幫助。如果想了解更多相關(guān)文章內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道。
文章標(biāo)題:vue移動(dòng)端實(shí)現(xiàn)ip輸入框問(wèn)題怎么解決-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)鏈接:http://bm7419.com/article36/hshpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站策劃、品牌網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容