關於angularjs架構中input按斷行符號事件游標跳轉到另一個input上

來源:互聯網
上載者:User

關於angularjs架構中input按斷行符號事件游標跳轉到另一個input上
我們項目裡用到angularjs 對應的包,沒有ng-keypress\ng-keydown。 所以,我們自己寫一些指令。 首先在,項目模組對應的module.js中寫指令

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斷行符號換行指令屬性
    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'){                        searchinputCtrl.focusInput( element );                    }                });            }        };    });      couchPotato.configureApp(module);    module.run(function($couchPotato){        module.lazy = $couchPotato;    });    return module;});html頁面:
######值得注意的是: 按下斷行符號 與提交表單按鈕;當輸入框是多個時。儲存######如果 type=button 則斷行符號不會提交表單;儲存######如果 type=submit則斷行符號會提交表單;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.