你如何自动对焦在iPhone Safari的表单字段? [英] How can you autofocus on a form field in iPhone Safari?

查看:147
本文介绍了你如何自动对焦在iPhone Safari的表单字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个特定的表单域在iPhone上的Safari浏览器中自动获取焦点。我认为这将是非常简单的,但我并没有设法得到这个工作。所以,这实际上是不可能的,或者我错过了一些超级明显的东西(我怀疑)?这里是我使用的代码:

 <!DOCTYPE html> 
< html>
< head>
< script type =text / javascript>
函数formfocus(){
document.getElementById('element')。focus();
}
window.onload = formfocus;
< / script>
< / head>
< body>

< form>
< input />
< input id =elementautofocus />
< input />
< / form>

< / body>
< / html>

你可以看到我试图通过js和一次HTML输入栏中的aufofocus属性。这个伎俩也没有。这可以在桌面浏览器上工作,但是当我在iPhone 4上打开页面时,没有任何骰子,也就是说,我必须通过点击其中一个表单域来手动设置焦点。


$ b $最终,我想在手机浏览器上打开网站,并专注于一个表单字段,包括打开的键盘开始打字。



感谢您的帮助!

解决方案

根据这个页面,出于可用性原因,iphone / ipad不支持自动对焦。 p>

I'm trying to have a particular form field get focus automatically in a Safari browser on iPhone. I thought this would be pretty straight-forward, but I'm not managing to get this working. So, is this actually not possible or am I missing something super-obvious (which I suspect)? Here is the code I'm using:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
   function formfocus() {
      document.getElementById('element').focus();
   }
   window.onload = formfocus;
</script>
</head>
<body>

<form>
<input/>
<input id="element" autofocus/>
<input/>
</form>

</body>
</html>

You can see I'm trying to get the focus twice, once via js and once via the HTML "aufofocus" attribute on the input field. Neither does the trick. This does work on desktop browsers, but when I open the page on my iPhone 4, no dice, that is, I have to set focus manually by clicking on one of the form fields.

Ultimately what I'd like is to open the website on the mobile browser and have focus on a form field, including the keyboard opened up to start typing.

Thanks for any help!

解决方案

According to this page, autofocus is not supported in iphone/ipad for usability reasons.

这篇关于你如何自动对焦在iPhone Safari的表单字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆