While typing in a text input field, printing the content typed in a div

前端 未结 5 2089
时光取名叫无心
时光取名叫无心 2020-12-13 03:08

I have a website where there is a empty box and a input text box. I want to be able to type something in that input box and have it be printed on the empty box.

HTM

5条回答
  •  旧巷少年郎
    2020-12-13 03:33

    You use the onkeyup event

    Searching with ids is a lot easier. Add ids to your elements as follows:

    JS

    var inputBox = document.getElementById('chatinput');
    
    inputBox.onkeyup = function(){
        document.getElementById('printchatbox').innerHTML = inputBox.value;
    }
    

    Here is a Live example

提交回复
热议问题