作为标题,我正在使用ionic和angularjs学习开发Web应用程序,但遇到了一些问题。我创建了一条指令,并尝试在输入字段按“ Enter”键时使键盘充当“ Tab”键。它与html中的静态标签完美配合。但是,当我使用ng-repeat生成输入字段时,它不起作用。
这是我的html:
<form enter-as-tab ng-controller="ListCtrl">
<ion-list>
<ion-item class="item item-dark" ng-repeat="item in items">
<input class="item-note" type="{{item.type}}">
{{item.name}}
</input>
</ion-item>
</ion-list>
</form>
这是我的控制器和指令:
.controller('ListCtrl',['$scope','$http',function($scope,$http){
$http.get('js/data.json').success(function(data){
$scope.items = data;
});
}])
.directive('enterAsTab', function () {
return {
"restrict" : "A",
"link" : function (scope, element, attrs) {
$('input').on("focus keypress", function(e) {
var inputs = $(this).closest('form').find(':input:visible,select:visible');
var nextInput = inputs.eq( inputs.index(this) + 1 );
if (e.keyCode === 13) {
nextInput.focus();
if(nextInput.attr('type')!=="submit")
e.preventDefault();
}
return true;
});
}}
})
希望你们能帮助我,非常感谢!
@charlietfl你的答案很完美,我找到了出现此错误的原因。我需要在angularjs之前声明jquery.js
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句