简体   繁体   English

我想把用户输入的文本打印到屏幕上,附加他们说的每一句话

[英]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.

相关问题 使用createTextNode方法附加用户输入的文本 - appending User entered text using createTextNode method 在用户输入的屏幕上分隔文本 - Separating text on the screen entered by the user 我想打印用户以html形式提交的数据 - I want to print the data the user has submitted in html form 执行 while 循环 - 我只想在用户在提示中输入 1 或 2 或在提示中选择取消时退出此循环 - Do while Loop - I only want to exit this loop when user has entered 1 or 2 into the prompt or selects the cancel in prompt 如果用户不存在于数据库中,我想打印错误文本 - I want to print error-text if user will not be present in the database 我正在制作一个基于文本的RPG,你可以在每个屏幕上说是或否,我需要帮助删除eventlistener - I am making a text-based RPG, and you can say yes or no on each screen, and I need help removing the eventlistener 用户输入文本后,如何使用 AJAX 更新我的数据库? - How can I update my Database using AJAX after the user has entered text? 用户将文本输入到文本区域后显示Div? - Show Div once a user has entered text into text area? 我想在输入字段输入后运行函数 - I want to run a function after an input field has been entered 如何计算用户在文本表单中输入的特定符号的数量 - How to count the amount of specifc symbols that a user has entered in a text form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM