[英]How to trigger enter key
This is the input bar and search button for my HTML 这是我的HTML的输入栏和搜索按钮
<div>
<div class="input-group search-bar">
<input type="text" class="form-control search-box" placeholder="Search people" autofocus="" ng-model="searchPeople">
<a ui-sref="index.peoplesearch({searchPeople : searchPeople})" class="input-group-addon search-box btn-primary btn-search">
<i class="glyphicon glyphicon-search"></i>
</a>
</div>
<div ng-repeat = "people in searchResultsPeople">
{{people.name}}
</div></div>
The controller for this search is 该搜索的控制器是
.controller('PeopleSearchController',function($scope,$http,$stateParams) {
var searchResultsPeople = $http.get(URL + SEARCH_PEOPLE + APIKEY + QUERY + searchPeople);
searchResultsPeople.then(
function (response) {
$scope.searchResultsPeople = response.data.results;
$scope.searchForPeople = true;
console.log(response.data.results);
},
function(response) {
$scope.message = "Error: "+response.status + " " + response.statusText;
}
);
I've an icon of search button and when I have an input in the search bar and click the button, it is working fine. 我有一个搜索按钮图标,当我在搜索栏中输入内容并单击该按钮时,它工作正常。 How to do the same function when I press enter after some text is entered in the input box ?
在输入框中输入一些文本后,按Enter键时如何执行相同的功能?
You can use ng-keyup
or ng-keydown
to capture user input and check to see if the enter key was pressed - if so, perform a specific action. 您可以使用
ng-keyup
或ng-keydown
捕获用户输入,并检查是否按下了Enter键-如果是,请执行特定操作。
HTML HTML
<input type="text" class="form-control search-box" ng-keyup="myKeyupHandler($event);"
placeholder="Search people" autofocus="" ng-model="searchPeople"/>
Controller 调节器
$scope.myKeyupHandler = function (event) {
var enter = 13;
if (event.keyCode === enter) {
// perform some action
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.