【发布时间】:2026-02-08 22:45:01
【问题描述】:
Here, When I'm clicking Enter Keyword, it goes to Next Line. Instead of that message have to be sent
【问题讨论】:
标签: node.js typescript ionic-framework ionic3 ionic4
Here, When I'm clicking Enter Keyword, it goes to Next Line. Instead of that message have to be sent
【问题讨论】:
标签: node.js typescript ionic-framework ionic3 ionic4
大概是这样的:
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回车,就不会发送了。
【讨论】: