这是今天遇到的一个问题;input表单手机号码验证不足11位弹出窗体并且input表单重新获得焦点。

但是mui.focus(document.getElementById('phonenum'));

document.getElementById('phonenum').focus();

这两行代码写上都没有效果,可以弹出键盘但是不能获得焦点。

 

 

<input type="text" name="phonenum" placeholder="请输入手机号 " style="border-radius:30px; height:50px; margin-top:50px;" >

 

$id('verify').addEventListener('tap',function(){

var mobile=$id('phonenum').value;

if(mobile.length!=11) 

mui.alert('您输入的位数不正确!'); 
mui.focus(document.getElementById('phonenum'));


return false; 
}


})

原因就是

在tap事件里边preventDefault后,会阻止当前element获得焦点。

所以在前面插入一行 ok问题解决了。

event.detail.gesture.preventDefault();//阻止默认事件
mui.focus(document.getElementById('phonenum'));

 

相关文章: