国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

JS如何實(shí)現(xiàn)手機(jī)端輸入驗(yàn)證碼效果

瀏覽:113日期:2024-05-08 17:56:44

之前在“掘金”上看到這樣一個(gè)demo 我覺得很有意思,于是今天把它搬下來,記在自己的“小本本”里也許會(huì)對(duì)以后的項(xiàng)目有點(diǎn)用,若要自己去實(shí)現(xiàn)這樣一個(gè)案例也能實(shí)現(xiàn),但是可能沒有那么“妙”。

想法:

1、使用label標(biāo)簽做顯示驗(yàn)證碼的框,

2、然后每個(gè)label for屬性指向同一個(gè) id 為vcode 的input,

3、為了能夠觸發(fā)input焦點(diǎn), 將input 改透明度樣式隱藏,

4、這樣就實(shí)現(xiàn)了 點(diǎn)擊label觸發(fā) input焦點(diǎn),調(diào)用鍵盤。

運(yùn)行效果:

JS如何實(shí)現(xiàn)手機(jī)端輸入驗(yàn)證碼效果

示例代碼:

結(jié)構(gòu)部分html:

<div class='app'> <h2 class='heading-2'>驗(yàn)證碼:</h2> <div class='v-code'> <inputref='vcode' type='tel'maxlength='6'v-model='code'@focus='focused = true'@blur='focused = false':disabled='telDisabled'> <labelfor='vcode' v-for='item,index in codeLength': v-text='codeArr[index]' > </label> </div></div>

css部分:

<style> * { margin: 0; padding: 0; box-sizing: border-box; } body { background-color: #ffffff; font-family: -apple-system, PingFang SC, Hiragino Sans GB, Helvetica Neue, Arial; -webkit-tap-highlight-color: transparent; } .app { padding-left: 20px; padding-right: 20px; padding-top: 60px; max-width: 320px; margin-left: auto; margin-right: auto; } .heading-2 { color: #333333; } .v-code { margin-top: 20px; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; -webkit-box-align: center; -ms-flex-align: center; align-items: center; position: relative; width: 280px; margin-left: auto; margin-right: auto; } .v-code input { position: absolute; top: 200%; opacity:0; } .v-code .line { position: relative; width: 40px; height: 32px; line-height: 32px; text-align: center; font-size: 28px; } .v-code .line::after { display: block; position: absolute; content: ’’; left: 0; width: 100%; bottom: 0; height: 1px; background-color: #aaaaaa; transform: scaleY(.5); transform-origin: 0 100%; } .v-code .line.animated::before { display: block; position: absolute; left: 50%; top: 20%; width: 1px; height: 60%; content: ’’; background-color: #333333; animation-name: coruscate; animation-duration: 1s; animation-iteration-count: infinite; animation-fill-mode: both; } @keyframes coruscate { 0% {opacity: 0 } 25% {opacity: 0 } 50% {opacity: 1 } 75% {opacity: 1 } to {opacity: 0 } } </style>

Javascript部分

1、通過CDN引入vue.js

<script src='https://cdn.bootcss.com/vue/2.5.16/vue.min.js'></script>

2、代碼

var app = new Vue({ el: ’#app’, data: { code: ’’, codeLength: 6, telDisabled: false, focused: false }, computed: { codeArr() {return this.code.split(’’) }, cursorIndex() {return this.code.length } }, watch: { code(newVal) {this.code = newVal.replace(/[^d]/g,’’)if (newVal.length > 5) { // this.telDisabled = true this.$refs.vcode.blur() setTimeout(() => { alert(`vcode: ${this.code}`) }, 500)} } }, })

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 天天草综合 | 欧美一级香蕉毛片 | 精品色综合 | 国产一级精品视频 | 久久一本色道综合 | 高清不卡一区二区三区 | 国产一区二区三区精品久久呦 | 国产一区二区免费不卡在线播放 | bt天堂国产亚洲欧美在线 | 日韩欧美亚州 | 99久久综合精品免费 | 一级特黄a免费大片 | 黄色理论视频 | 伊人久热这里只有精品视频99 | 久久橹| 成年人免费看 | 精品国产精品a | 玖玖爱精品 | 鲁大师成人精品视频 | 亚洲欧美精品中文字幕 | 久久国产精品永久免费网站 | 欧洲97色综合成人网 | 日日撸夜夜操 | 国产欧美精品综合一区 | 性欧美美国级毛片 | 精品久久香蕉国产线看观看亚洲 | 亚洲综合美女 | 草草影院ccyy国产日本欧美 | a级欧美片免费观看 | 欧美xxxxx九色视频免费观看 | 色婷婷激婷婷深爱五月老司机 | 欧美一级网站 | 窝窝午夜精品一区二区 | 国产一区二区精品在线观看 | 中文字幕精品视频 | 97在线观看成人免费视频 | 亚洲人成影院在线高清 | 玖玖精品在线视频 | 午夜欧美日韩在线视频播放 | 男吃女下面刺激视频免费 | 搞黄网站免费看 |