选择 <input> 时不显示键盘仅限 iOS

编程入门 行业动态 更新时间:2024-10-28 06:26:10
本文介绍了选择 <input> 时不显示键盘仅限 iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

对于我网站上的特定字段,在 Safari iOS 上运行时,我的网站上没有显示键盘.它适用于网络和 Android chrome.

只有当我在 safari 上选择多标签按钮并再次返回网站时,键盘才会显示.然后当我选择该字段时键盘会出现.

当我选择改变键盘输入行为的多标签按钮时,有哪些变化?

更新:

点击输入文本字段前(具有只读属性):

<span class="label">密码</span><br><input type="password" name="loginValidVO.password" maxlength="15" required="true" autocomplete="off" readonlyonfocus="this.removeAttribute('readonly');"类=占位符"id=密码">

单击文本字段后(将触发 onfocus 事件并删除 'readonly' 属性),但是键盘仍然没有显示.

<span class="label">密码</span><br><input type="password" name="loginValidVO.password" maxlength="15" required="true" autocomplete="off"onfocus="this.removeAttribute('readonly');"类=占位符"id=密码">

我们是否需要一些东西来刷新视图,以便删除输入字段的只读属性生效?

Android 与上面的代码完美配合,只是想知道为什么它只发生在 iOS 设备(Safari 和 chrome)上

解决方案

尝试为 touchstart 事件添加附加属性 - ontouchstart,它执行相同的 javascript:

<input type="password" name="extLoginValidVO.password" maxlength="20" required="true" autocomplete="off"ontouchstart="this.removeAttribute('readonly');"onfocus="this.removeAttribute('readonly');"类=占位符"id="密码"只读>

您可能也希望保持 onfocus,因为桌面浏览器需要它.这是我使用的 jsfiddle:https://jsfiddle/u5g7t4c1/4/

For a particular field on my website, the keyboard doesn't show up on my website when running it on Safari iOS. It works on the web and Android chrome.

The keyboard will only show up if I select the multitab button on safari, and return to the website again. Then the keyboard will show up when I select the field.

What are the things that change when I select the multitab button which changes the input behaviour of the keyboard?

Update:

Before clicking the input text field (with readonly property):

<div class="form-cell password">
    <span class="label">Password</span><br>
    <input type="password" name="loginValidVO.password" maxlength="15" mandatory="true" autocomplete="off" readonly
        onfocus="this.removeAttribute('readonly');" class="placeholder" id="password">
</div>

After clicking the text field (will trigger the onfocus event and remove the 'readonly' property), however the keyboard still doesn't show up.

<div class="form-cell password">
    <span class="label">Password</span><br>
    <input type="password" name="loginValidVO.password" maxlength="15" mandatory="true" autocomplete="off"
        onfocus="this.removeAttribute('readonly');" class="placeholder" id="password">
</div>

Do we need something to refresh the view so that the removal of input field readonly property will take effect?

Android works flawlessly with the code above, just wondering why it happens only on iOS device (both safari and chrome)

解决方案

Try adding additional attribute for the touchstart event - ontouchstart, which executes the same javascript:

<input type="password" name="extLoginValidVO.password" maxlength="20" mandatory="true" autocomplete="off" 
       ontouchstart="this.removeAttribute('readonly');" 
       onfocus="this.removeAttribute('readonly');" 
       class="placeholder"
       id="password"
       readonly>

You might want to keep onfocus too, since it's needed for desktop browsers. Here's the jsfiddle that I used: https://jsfiddle/u5g7t4c1/4/

这篇关于选择 &lt;input&gt; 时不显示键盘仅限 iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 08:33:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1039174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:仅限   键盘   lt   amp   input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!