NG-重复和文本区域聚焦

ng-repeat and textarea focused

本文关键字:区域 聚焦 文本 NG-      更新时间:2023-09-26

UPDATE: "textareashow" 是:

<div class="col-md-10 col-md-offset-1" data-ngshow="textareashow">
   <div id="replyBox">
      <textarea cols="65" rows="7" maxlength="300" data-ng-model="texta" autofocus="autofocus" data-ng-focus="focus()" data-ng-blur="blur()"></textarea>
      <br>
      <button class="btn btn-info" type="submit">Submit answer</button>
   </div>
</div>

我有ng-repeat,在循环中我有:

<button class="btn btn-default" id="answers_button" data-ng-click="textareashow = !textareashow">Answer</button>
<textarea cols="65" rows="7" data-ng-model="texta" autofocus="autofocus" data-ng-focus="focus()" data-ng-blur="blur()"></textarea>

我希望如果用户单击"答案"button将显示textarea。它正在工作,但只有一次,如果我单击它并关闭,然后单击另一个答案button - textarea将不会聚焦。

更新:"textareashow" at self place

像这样更改您的 html:

<button class="btn btn-default" id="answers_button" data-ng-click="textareashow = !textareashow;doAnswer($event)">Answer</button>
<textarea  cols="65" rows="7" data-ng-model="texta" autofocus="autofocus" data-ng-focus="focus()" data-ng-blur="blur()"></textarea>

在您的控制器 js 中:

$scope.doAnswer = function(event){
    angular.element(event.target).next().focus();
}