3

При вводе данных в input они должны сразу же отображаться в .innerHTML. Как это сделать?

var one = document.getElementById('one');
var here = document.getElementById('here');



var par = document.createElement('p');
par.innerHTML = parseInt(one.value);
here.appendChild(par);
#here {
  border: 1px solid #000;
  width: 150px;
  margin: 10px;
  line-height: 50px;
  text-align: center;
}
<input type="text" id="one">
<div id="here"></div>

1 ответ 1

7

С помощью обработчика события input

document.getElementById('one').addEventListener('input', function() {
  document.getElementById('here').innerText = this.value;
});
<input type="text" id="one">
<div id="here"></div>

0

Ваш ответ

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

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