【发布时间】:2020-05-29 22:26:52
【问题描述】:
我的应用程序中有一个搜索输入框。每当我单击按钮时,搜索输入就会打开。但它不是自动对焦。
请看我的代码,
$scope.goSearch = function () {
$scope.$broadcast("focusTextInput");
}
<a class="nav-link-img search-icon" ui-sref="search" ng-click="goSearch();"><img src="assets/images/searchIconDefault.svg"/></a>
<input type="search" autofocus class="form-control search-field" placeholder="Search Card" ng-model="search" focus-on="focusTextInput">
app.directive("focusOn", function ($timeout) {
return {
restrict: "A",
link: function (scope, element, attrs) {
scope.$on(attrs.focusOn, function (e) {
$timeout((function () {
element[0].focus();
}), 10);
});
}
};
});
这是我正在使用的代码。
- ) 唯一的问题是,光标闪烁焦点在台式机、笔记本电脑中有效,但在 ipad 和 ipad pro 中无效。
你能告诉我该怎么做吗?
【问题讨论】:
标签: javascript html angularjs