如何在列表中使用 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}}

更新於:28-1 月-2020

385 瀏覽

開啟你的 事業

完成課程可以獲得認證

開始
廣告
© . All rights reserved.