【问题标题】:lost focus on textarea when keyboard appear键盘出现时失去对文本区域的关注
【发布时间】:2014-04-06 23:32:00
【问题描述】:

我有一个网络应用程序(不是安卓应用程序)

我的页面中有很多 textarea,如下例所示,如果我点击 iPad 中的 textarea,则会出现键盘并且我在 textarea 中失去焦点。

我的问题:即使出现键盘,我怎样才能保持焦点?不使用 jquery mobile。

例子

<html>
    <head>
        <title>My Page</title>
    </head>

    <body>
        <form name="myform" action="" method="POST">
            <div align="center">
                This is outside the area<br><br>
                <textarea cols="40" rows="1" name="myname">
                      Now we are inside the area - which is nice.
                </textarea>
                <br><br>
                And now we are outside the area again.
            </div>
             <div align="center">
                This is outside the area<br><br>
                <textarea cols="40" rows="1" name="myname">
                      Now we are inside the area - which is nice.
                </textarea>
                <br><br>
                And now we are outside the area again.
            </div>
             <div align="center">
                This is outside the area<br><br>
                <textarea cols="40" rows="1" name="myname">
                      Now we are inside the area - which is nice.
                </textarea>
                <br><br>
                And now we are outside the area again.
            </div>
        </form>
    </body>
</html>

【问题讨论】:

  • 那你为什么用Android标签标记这个问题?
  • 从问题中移除 android 标签
  • 因为是android相关的问题

标签: html ios keyboard touch textarea


【解决方案1】:

你可以试试 HTML autofocus 属性:

<textarea cols="40" rows="1" name="myname" autofocus>
  Now we are inside the area - which is nice.
</textarea>

不确定onclick="autofocus" 是否有效。 (不要相信它。你将需要 javascript)

【讨论】:

    猜你喜欢
    • 2011-11-20
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    • 1970-01-01
    • 2014-02-22
    • 2020-03-05
    相关资源
    最近更新 更多