1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > angularjs中按回车事件_关于angularjs框架中input按回车事件光标跳转到另一个input上...

angularjs中按回车事件_关于angularjs框架中input按回车事件光标跳转到另一个input上...

时间:2020-12-13 01:36:23

相关推荐

angularjs中按回车事件_关于angularjs框架中input按回车事件光标跳转到另一个input上...

我们项目里用到angularjs 对应的包,没有ng-keypress\ng-keydown。 所以,我们自己写一些指令。 首先在,项目模块对应的module.js中写指令

class="hljs javascript">define([

'angular',

'angular-couch-potato',

'angular-ui-router',

'angular-resource'

], function (ng, couchPotato) {

'use strict';

var module = ng.module('app.handOverWithdrawals', [

'ui.router',

'ngResource'

]);

##在html页面中 设置angularjs全局的指令属性

module.directive('searchinput', function () {

return {

restrict: 'A',

controller: function(){

var allInputs = [];

this.getAll = function( ele ){

allInputs.push( ele );

};

this.focusInput = function( ele ){

angular.forEach(allInputs, function( input,index ) {

//if (ele === input) {

// allInputs[index+1][0].focus();

//}

if ( ele === input && allInputs[index+3] ) {

allInputs[index+3][0].focus();

}

});

};

}

};

});

##在html页面中input输入框,设置angularjs回车换行指令属性

class="hljs lua"> module.directive('enternextline', function () {

return {

restrict: 'A',

require : '^searchinput',

link: function (scope, element, attrs, searchinputCtrl) {

searchinputCtrl.getAll( element );

element.bind('keypress',function(event){

if(event.keyCode == '13'){

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。