目前,当我在搜索栏中输入三个字母时,自动完成功能将开始工作,并且键盘开始在移动设备上隐藏。
我使用的代码是
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/