【问题标题】:How to send the message by one Enter Click?如何一键发送消息?
【发布时间】:2026-02-08 22:45:01
【问题描述】:

【问题讨论】:

    标签: node.js typescript ionic-framework ionic3 ionic4


    【解决方案1】:

    大概是这样的:

    const textarea = document.getElementById("textinput");
    var shift = false;
    var text;
    var lastkey;
    window.onkeydown = function(evt) {
      if (!evt.shiftKey) {
        shift = false;
      }
      else shift = true;
      lastkey = evt.key.toLowerCase();
    }
    textarea.oninput = function() {
      if (shift == false) {
        if (!lastkey.includes("enter")) text = this.value;
        else document.getElementById("sendButtonID").click();
      }
      else text = this.value;
    }
    <textarea id="textinput"></textarea>
    <button id="sendButtonID" onclick="console.log('Sent: ' + text); textarea.oninput(); textarea.value = ''">Send</button>

    如果你按shift回车,就不会发送了。

    【讨论】: