這是今天遇到的一個問題;input表單手機號碼驗證不足11位彈出窗體而且input表單從新得到焦點。ui
可是mui.focus(document.getElementById('phonenum'));事件
document.getElementById('phonenum').focus();element
這兩行代碼寫上都沒有效果,能夠彈出鍵盤可是不能得到焦點。get
<input type="text" name="phonenum" placeholder="請輸入手機號 " style="border-radius:30px; height:50px; margin-top:50px;" id="phonenum">input
$id('verify').addEventListener('tap',function(){io
var mobile=$id('phonenum').value;mui
if(mobile.length!=11)
{
mui.alert('您輸入的位數不正確!');
mui.focus(document.getElementById('phonenum'));event
return false;
}function
})mobile
緣由就是
在tap事件裏邊preventDefault後,會阻止當前element得到焦點。
因此在前面插入一行 ok問題解決了。
event.detail.gesture.preventDefault();//阻止默認事件 mui.focus(document.getElementById('phonenum'));