[英]Using React, click the first input show the second input, how to auto focus to the second input?
[英]How to auto focus on first input field using angular
我的項目中有20個html頁面,我需要實現一個通用的角度代碼指令以自動關注所有頁面的第一個輸入字段。
您可以嘗試如下操作:
angular.module('utils.autofocus', [])
.directive('autofocus', ['$timeout', function($timeout) {
return {
restrict: 'A',
link : function($scope, $element) {
$timeout(function() {
$element[0].focus();
});
}
}
}]);
// <input type="text" autofocus>
您也可以嘗試ng-autofocus
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.