0

Написал код:

<textarea cols="100" placeholder="Напишите ваше сообщение."></textarea>
<input type="submit" value="Отправить">

Как сделать так что бы все сообщение которые были оставлены в textarea отображались ниже?

1 ответ 1

2

const form = document.getElementById("form");
const textarea = document.getElementById("textarea");
const messages = document.getElementById("messages");

form.onsubmit = function () {
  if (textarea.value) {
    const message = document.createElement("p");
    message.innerHTML = textarea.value;
    messages.appendChild(message);
    textarea.value = "";
    textarea.focus()
  }
  return false;
}
<form id="form">
  <textarea id="textarea"></textarea>
  <button>Отправить</button>
</form>
<div id="messages"></div>

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.