问题
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