javascript - 单击后按钮保持焦点

标签 javascript html angular angular-router

我有一个按钮,单击该按钮会导航到另一条路线。相关代码为:

<button (click)="goBack()" mat-button
      aria-label="Previous Screen" role="navigation">
      <mat-icon>keyboard_arrow_left</mat-icon>
</button>

以及点击处理程序:

  goBack() {
    this.location.back();
  }

当我单击按钮时,路线会发生变化,但按钮会获得焦点。难道是我做错了什么?

Demonstration

最佳答案

您想要查看 HTMLElement.blur() 功能。我对 Angular 不太熟悉,但您需要有权访问该事件及其目标才能执行此操作。

这样的事情应该有效:

<button (click)="goBack($event)" mat-button
      aria-label="Previous Screen" role="navigation">
      <mat-icon>keyboard_arrow_left</mat-icon>
</button>

对于 JS:

goBack(event) {
    event.target.blur()
    this.location.back();
  }

关于javascript - 单击后按钮保持焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53171829/

相关文章:

javascript - ExtJS TreeGrid 中的复选框列

javascript - php中如何获取组合框的值

javascript - 检测 iframe 对象中的 src/location 变化

angular - 对 Component 的宿主文档点击的巨大性能影响 (Angular2)

javascript - 导入自定义模块时获取 'Cannot read property ' ɵmod' of undefined' [Angular 11]

javascript - 如何读取浏览器中所有存储的 Cookie

javascript - Angular : how to iterate through all indices in an array except the final index using ng-repeat

html - 如何在表格中隐藏大纲

html - 通过 SVG 路径为 "div"设置动画

javascript - 如何将值从兄弟组件传递到 Angular 6 中的路由器导出?