SetFocus does not work on iPad

≯℡__Kan透↙ 提交于 2019-12-05 02:59:37

问题


We found that this code works on a PC with: IE, Safari and FireFox. However on an iPad or iPhone with Safari it does not auto focus on a textbox. We cannot touch the screen and click the textbox, we need the auto focus. Any tips here?

thanks!

<script language='JavaScript'>
<!--
function SetFocus()
{
    document.form1['txtCode'].focus();
}
window.onload = SetFocus;
// -->
</script>

回答1:


Unfortunately, it appears Mobile Safari does not support this behaviour, by design.

http://www.quora.com/Mobile-Safari-iPhone-or-iPad-with-JavaScript-how-can-I-launch-the-on-screen-keyboard




回答2:


<body onload="document.getElementById('txtCode').focus();">
    <form>
        <input type="text" value="Text Here" name="txtCode" id="txtCode" />
    </form>
</body>

Try This



来源:https://stackoverflow.com/questions/5118885/setfocus-does-not-work-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!