如何清除输入搜索而不隐藏键盘? (移动)
问题描述:
我使用的离子/ AngularJS,这就是我的问题,我每次清理输入时,键盘会消失,我不希望出现这种情况如何清除输入搜索而不隐藏键盘? (移动)
<ion-header-bar ng-show="searchBoxEnabled">
<div>
<input type="search"
ng-model="query">
<div ng-show="query"
ng-click="query=''"> <!--must ONLY clean the input, but is
also disappearing the keyboard-->
</div>
</div>
<!--must clean the input and disappear the keyboard,
this one is working properly-->
<div ng-click="hideSearchBox(); query=''">
|Cancel
</div>
</ion-header-bar>
,并在JavaScript方面我有这对夫妻为了功能的显示和隐藏输入
$scope.showSearchBox = function() {
$scope.searchBoxEnabled = true;
};
$scope.hideSearchBox = function() {
$scope.searchBoxEnabled = false;
};
答
我同意,这可能是针对导致键盘走开输入的blur
事件。
你可以与上下面点击输入重新调整(虽然我没有办法来验证这是否会导致与键盘闪烁)的按钮指令解决这个问题。
在这里你传递你想重新聚焦到该元素的ID说明性的例子:
app.directive("refocus", function() {
return {
restrict: "A",
link: function(scope, element, attrs) {
element.on("click", function() {
var id = attrs.refocus;
var el = document.getElementById(id);
el.focus();
});
}
}
});
和用法是:
<input id="foo" ng-model="newItem">
<button ng-click="doSomething(newItem)" refocus="foo">add</button>
+0
如果你添加的离子束.js文件的代码将停止工作 code.ionicframework.com/nightly/js/ionic.bundle.js – Gino 2017-05-08 17:35:21
我不认为它清楚了隐藏键盘的输入,它是点击按钮。单击该按钮会在输入上触发模糊事件。在您的hideSearchBox()函数中,重新调整输入元素。这可能会导致键盘隐藏然后重新出现。 – 2015-02-11 22:22:37
那么,我能做些什么? @ConnorFinnMcKelvey – NietzscheProgrammer 2015-02-11 22:45:44
在'ng-click'中,您可以重新对焦输入,以便键盘再次出现。我想你会想为此创建一个指令。或者让用户自己再次点击输入。 – Rhumborl 2015-02-11 23:02:18