自动完成功能使您不再关注移动视图

时间:2018-10-08 09:34:11

标签: javascript jquery magento search

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

我使用的代码是

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

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

当我将其用于android设备时,自动完成功能将删除键盘,但立即将其重新带回,但ios将开始一次又一次地隐藏它。

还有另一种可能性,就是说“阻止所有可以消除焦点的东西”或“当失去焦点时立即将其重新带回来”?

1 个答案:

答案 0 :(得分:1)

尝试下面的代码段

$("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" />