Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

ตั้งโฟกัสที่ text input ในรายการด้วย AngularJS และ HTML5

เพื่อตั้งโฟกัสที่ text input ในรายการ ลองโค้ดด้านล่าง:

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}}