为什么iOS移动无法使用focus() [英] why iOS mobile cannot use focus()

查看:94
本文介绍了为什么iOS移动无法使用focus()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JavaScript函数focus(),但是在Safari浏览器上不起作用.我该如何解决这个问题?

I'm trying to use the javascript function focus(), but it does not work on safari mobile. How do I fix this problem?

<html lang="en">
   <head>
      <meta charset="UTF-8">
      <title>demo</title>
      <script type="text/javascript">
         window.onload=function() {
           document.getElementById('username').focus();
         }
      </script>
   </head>
   <body>
     <input type="text" id="username" >
     <input type="text" >
   </body>
</html>

推荐答案

出于安全原因,iOS不允许自动触发.focus().

iOS does not allow .focus() to be fired automatically for security reason.

这篇关于为什么iOS移动无法使用focus()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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