【问题标题】:Ionic 2 Prompt Alert focus on text inputIonic 2 Prompt Alert 专注于文本输入
【发布时间】:2017-08-09 16:47:18
【问题描述】:

我正在为 android 和 ios 创建一个 ionic 2 应用程序。我有一个提醒用户输入文本的警报控制器,但是当弹出警报时,我希望键盘专注于输入,并突出显示占位符文本。目前,您必须点击文本输入才能弹出键盘。这可以实现吗?

这是我的警报控制器代码:

let prompt = this.alertCtrl.create({
    title: this.name,
    message: this.nameMessage,
    inputs: [
      {
        name: 'name',
        placeholder: this.name
      },
    ],
    buttons: [
      {
        text: this.save,
        handler: data => {
          resolve(data.name);
        }
      }
    ],
    enableBackdropDismiss: false
  });
  prompt.present();

【问题讨论】:

    标签: ionic-framework ionic2


    【解决方案1】:

    这是我的解决方案。

    第一

    inputs: [
        {
          id: "autofocu",
          ......
        }
      ],
    

    然后

    alert.present()
    .then(() => {
      document.getElementById('autofocu').focus();
    })
    .catch()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-05
      • 2018-09-22
      相关资源
      最近更新 更多