贺捷生,朴奉珠,执掌盛唐
本文实例为大家分享了vue实现短信验证码输入框的具体代码,供大家参考,具体内容如下
先上最终效果 (此处代码显示的是短信验证码框的效果 其余部分并未放上去)
html
<div class="code"> <input id="first" class="inputstyle" v-model="code[0]" style="border-top-left-radius: 12px; border-bottom-left-radius: 12px;" type="text"/> <input id="second" class="inputstyle" v-model="code[1]"style="border-left:1px solid #c6c6c6;" type="text"/> <input id="third" class="inputstyle" v-model="code[2]"style="border-left:1px solid #c6c6c6;" type="text"/> <input id="forth" class="inputstyle" v-model="code[3]" style="border-left:1px solid #c6c6c6;" type="text"/> <input id="fifth"class="inputstyle" v-model="code[4]" style="border-top-right-radius: 12px; border-bottom-right-radius: 12px; border-left:1px solid #c6c6c6;" maxlength="1" type="text"/> </div>
js
data (){ return { smscode:'', code:new array(5), codeid:['first','second','third','forth','fifth'] } }, watch:{ code:function(newvalue,oldvalue){ console.log('newvalue.length'+newvalue.length) let tempvalue='' for(let i=0;i<newvalue.length;i++){ if(i==5){ console.log(i) break } if(newvalue[i]){ tempvalue=tempvalue+newvalue[i] } } this.smscode=tempvalue console.log('smscode '+this.smscode) let m=tempvalue.split("") let location=0 for(let i=0;i<newvalue.length;i++){ if(m[i]&&i<5){ location++ newvalue[i]=m[i] }else{ newvalue[i]='' } } // console.log(this.codeid[i]) if(location<1){ location=1 }else if(location>5){ location=5 } document.getelementbyid(this.codeid[location-1]).focus() } },
css
.inputstyle{ width:20%; height:100%; text-align:center; border:none; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
VUE+elementui组件在table-cell单元格中绘制微型echarts图
Vue通过getAction的finally来最大程度避免影响主数据呈现问题
vue 路由懒加载中给 Webpack Chunks 命名的方法
网友评论