蘋果手機focus沒有效果 鍵盤跳不出來
阿新 • • 發佈:2018-04-28
ted until cli tex ont 渲染 暫時 觸發 有用
原因:
In iOS, Safari is now apparently remembering that the element was focussed but not actually focussing it until a touch down event.
It is then blindly sending a click event to whichever element received the touch up.
在IOS中只有用戶主動觸發的事件才能使focus生效,所以可以在focus之前的用戶觸發的事件中用focus()方法
比如VUE中 HTML:
<p id="click-ele">點擊評論</p>
<input id="input" v-show="isInputShow" type="text"></input>
js如下:
document.getElementByID(‘click-ele‘).addEventListener(‘click‘,function(){
vue.isInputShow = true
document.getElementById(‘input‘).focus()
},false)
這樣點擊評論後,input標簽可以focus,鍵盤也會跳出來。
註意有兩點:
(1)document.getElement要在mounted 即DOM結構渲染好之後用,不然獲取不到元素。
(2)P標簽上直接使用VUE中的@click=“handlerClick”事件不能生效,原因暫時未知,用原生事件沒問題。
蘋果手機focus沒有效果 鍵盤跳不出來