我正在关注在 AngularJS API 文档中找到的“typeahead”代码:http://angular-ui.github.io/bootstrap/
我可以通过按回车键用第一个选项填充文本框,但由于某种原因,我无法使用箭头键(向上和向下)从自动完成列表中选择任何项目,但在他们的示例中, 我可以。
这可能是什么问题?
** 注意,这是一个 Express 项目,我使用的是 Jade 引擎。
头文件
link(rel='stylesheet', href='/css/bootstrap.css')
script(src='/js/jquery-2.1.1.min.js')
script(src='/js/angular.min.js')
script(src='/js/bootstrap.min.js')
script(src='/js/ui-bootstrap-tpls-0.11.0.min.js')
script(src='/js/index.js')
index.html 中的部分代码
<div ng-controller="TypeaheadCtrl" class="col-md-5 ng-scope">
<pre class="ng-binding">Model {{selected}}</pre>
<input type="text" ng-model="selected" placeholder="item name" typeahead="item for item in items | filter:$viewValue | limitTo:8" class="form-control" >
</div>
索引.js
var App = angular.module('myApp', ['ui.bootstrap']);
function TypeaheadCtrl( $scope, $http ) {
$scope.selected = undefined;
$scope.items = ['Chicken', 'Corn', 'Ice Cream', 'Cereal'];
}
经过更多尝试后,我发现我的浏览器还有另一个自动完成功能。可能是 chrome 自动填充?也许我的上下正在用于此而不是用于我的网络应用程序?如果是这样,您将如何通过代码禁用它,以便我可以仅在该页面上将其用于 Angular 的自动完成?
最佳答案
尝试设置 autocomplete="off"
在 <form>
或 <input>
水平。
autocomplete
的文档可以在 Mozilla's <input>
section 中找到
关于javascript - AngularJS:为什么我不能使用箭头键从文本框中选择自动完成列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24644601/