如何利用 AngularJS 和 HTML5 對列表中的文字輸入設定焦點


如需設定列表中文字輸入的焦點,試試下列程式碼

newApp.directive('focus', function () {
   return function (scope, element, attrs) {
      attrs.$observe('focus', function (newValue) {
         newValue === 'true' && element[0].focus();
      });
   }
});

以下為 HTML

<input type="text" ng-model="cues[$index].text" focus="{{cue.isNewest}}"
class="input-xlarge" />{{cue.isNewest}}

已更新於:2020 年 1 月 28 日

已瀏覽 385 次

開啟你的事業

完成課程獲得認證

開始學習
廣告
© . All rights reserved.