h5 input 禁止彈出虛擬鍵盤


最近開發一個觸屏的一個項目,需要用到自己的鍵盤樣式,需要屏蔽虛擬的鍵盤,參考了一些網上的資料,最實用的還是利用input的屬性 :readonly 

以element-ui 為例 設置 readOnly='readOnly'


<
el-input v-model="input" placeholder="請輸入內容" readOnly='readOnly'></el-input>

//input
<input placeholder="請輸入內容" readOnly='readOnly'></input>

在最近的項目發現element-ui input框在移動端沒有屏蔽,得到焦點的時候還是能彈出輸入法,最后發現了問題的所在,下面就是解決的方法:

<el-input v-model="input" placeholder="請輸入內容" readOnly='readOnly' ref='input'></el-input>

其實我們這樣寫,readOnly這個屬性作用的是最外層的<div>標簽

<div class="el-input" 
readonly="readonly" ><input autocomplete="off" placeholder="請輸入內容" type="text" rows="2" validateevent="true" class="el-input__inner"></div>

我們可以在初始化的時候設置input的屬性,這樣就解決問題了

this.$nextTick(()=>{ this.$refs.input.$el.children[0].setAttribute('readOnly','readOnly') })


 
         






 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM