[英]i want to take the text a user has entered and print it to the screen, appending each new thing they say
I'm trying to make a chat system.我正在尝试制作一个聊天系统。 So when a user types what they want to say, it's printed to the chat.所以当用户输入他们想说的话时,它会被打印到聊天中。 but I need to know how to keep appending to this chat??但我需要知道如何继续附加到这个聊天?? here's the outline so far:这是到目前为止的大纲:
<textarea name="chat" id="chat" placeholder="Comment text." rows="2"
cols="35" required></textarea><br><br>
<button onclick="myFunction()">send</button>
<p id="theChat"></p>
<script>
var textareaValue = document.getElementById('chat').value
var chatArray = [];
document.getElementById("theChat").innerHTML = chatArray;
function myFunction() {
chatArray.unshift(textareaValue);
document.getElementById("theChat").innerHTML = chatArray;
}
You'll have to append to the existing text:您必须附加到现有文本:
document.getElementById("theChat").innerHTML = document.getElementById("theChat").innerHTML + chatArray;
Do take some time to look into concatenating strings as that might help your development in future.请花一些时间研究连接字符串,因为这可能有助于您将来的开发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.