【问题标题】:ionic 2 - keep keyboard open when clicking send buttonionic 2 - 单击发送按钮时保持键盘打开
【发布时间】:2017-10-01 19:24:39
【问题描述】:

当输入/文本区域成为焦点时,ionic 中的键盘打开(?)。

但是当我点击发送按钮时,键盘消失了。

即使我调用键盘插件的keyboard.show()方法,它也会先消失,然后再出现。

有解决办法吗?

<textarea id="chat-text-area></textarea>

sendMessage() {
    if(window.cordova){
        this.keyboard.show()
    }
    if(this.form.valid){
        this.service.post(this.form.value).subscribe(res=>{
            document.getElementById('chat-text-area').focus()
        })
    }
}

【问题讨论】:

    标签: angular keyboard ionic2 focus textarea


    【解决方案1】:

    将此添加到您的发送按钮:

    (mousedown)="$event.preventDefault(); sendMessage($event)"
    

    希望对你有帮助:)

    【讨论】:

    • 谢谢!从 Ionic 5/6 开始,这仍然有效。唯一要记住的是,如果页面显示ion-loading,例如焦点仍将丢失(在按钮中使用微调器图标将为您提供类似的用户体验,并且键盘将保持可见)。跨度>
    【解决方案2】:

    你能在隐藏事件中注入你的逻辑吗?

    window.addEventListener('native.keyboardhide', keyboardHideHandler);
    
    function keyboardHideHandler(e){
        if (something) // put your condition here
            e.preventDefault();
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-02
      • 2015-09-13
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      相关资源
      最近更新 更多