【问题标题】:Angular iOS text field focusAngular iOS 文本字段焦点
【发布时间】:2020-08-10 21:05:30
【问题描述】:

当我打开带有输入的 div 时,我需要打开移动键盘。我试图为输入设置焦点

 this.changeCityInput.nativeElement.focus();

当我点击父 div 时触发。单击父 div 子扩展并显示输入字段后

但它在 ios 上不起作用,对于桌面和 android 都可以正常工作。

还有

document.body.ontouchend = () => {
        this.changeCityInput.nativeElement.focus();
      };
setTimeout(() => {
  this.renderer.selectRootElement(this.changeCityInput.nativeElement).focus();

  this.changeCityInput.nativeElement.focus();
}, 500);

不起作用。 将焦点设置在输入上的正确方法是什么?


更新: 在 MacOS 上正常工作

【问题讨论】:

    标签: javascript angular


    【解决方案1】:

    focus() 不适用于禁用按钮 我模拟禁用的操作

    默认情况下,当我使用输入打开 div 时,我会专注于它,完成后我使用 blur() 来取消聚焦 el

    【讨论】:

      猜你喜欢
      • 2017-07-28
      • 2010-11-09
      • 1970-01-01
      • 2011-11-23
      • 2022-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多