Javascript 检测文本区域外的单击

Javascript 检测文本区域外的单击,javascript,html,angular,Javascript,Html,Angular,当用户在我的文本区域中输入文本时,我的窗口会改变颜色。我希望当它在文本区域外单击时,它会像以前一样替换颜色 <textarea class="chat-input" id="textarea" rows="2" cols="50" (keyup)="detectTextarea($event)"> </textarea> detectTextarea(event: any): any

当用户在我的文本区域中输入文本时,我的窗口会改变颜色。我希望当它在文本区域外单击时,它会像以前一样替换颜色

<textarea class="chat-input"
              id="textarea"
              rows="2" cols="50"
              (keyup)="detectTextarea($event)">
</textarea>


detectTextarea(event: any): any {
   this.changeColor = true;
   var textarea = document.getElementById("textarea");
}
您可以收听事件以了解用户何时退出文本区域。

您可以收听事件以了解用户何时退出文本区域。

如下更改:

<textarea class="chat-input"
    id="textarea"
    rows="2" cols="50"
    (focus)="func()"
    (blur)="otherFunc()"
    (keyup)="detectTextarea($event)">
</textarea>
更改如下:

<textarea class="chat-input"
    id="textarea"
    rows="2" cols="50"
    (focus)="func()"
    (blur)="otherFunc()"
    (keyup)="detectTextarea($event)">
</textarea>

10公里,祝贺你)10公里,祝贺你)这可能会帮助你。链接:这可能对你有帮助。链接:非常感谢!!最后很简单:)很高兴我能帮上忙!谢谢!!最后很简单:)很高兴我能帮上忙!
func() {
    this.changeColor = true;
  }
  otherFunc() {
    this.changeColor = false;
  }
}