javascript - 自动完成功能消除了对移动 View 的关注

标签 javascript jquery magento search

目前,当我在搜索栏中输入三个字母时,自动完成功能将开始工作,并且键盘开始在移动设备上隐藏。

我使用的代码是

jQuery("input#search").focus();

jQuery("input#search").blur(function() {
    setTimeout(function() { jQuery("input#search").focus(); }, 0);
});

当我在 Android 设备上使用此功能时,自动完成功能将删除键盘,但会立即将其恢复,但 ios 将开始一次又一次地隐藏它。

是否还有另一种可能性,只是说“阻止所有会移除焦点的内容”或“当失去焦点时立即将其恢复”?

最佳答案

尝试下面的代码片段

$("input#search").focus();

    $("input#search").blur(function(e) {
        e.preventDefault();
        e.stopPropagation();
        $( this ).prop( "disabled", true );
        $( this ).prop( "readonly", true );
        setTimeout(function() { $("input#search").focus(); }, 100);
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" id="search" />

关于javascript - 自动完成功能消除了对移动 View 的关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52699326/

相关文章:

javascript - 选择多个 jQuery 对象

jquery - AJAX 从 Twitter 搜索读取 JSON 数据不起作用

jquery - 在移动设备上使用悬停子菜单引导导航

javascript - 单击浏览器后退按钮时隐藏加载 gif?

apache - 从 htaccess 重写规则中删除硬编码的 url

magento - 如何将自定义图像字段添加到 Magento 中的类别?

javascript - 使用 jquery 更新类

javascript - 单击某个元素时如何显示接下来的 3、6、9 等子元素?

javascript - 如何在 Antd 中使用嵌套的单选按钮组?

php - magento中资源模型和模型的区别