简体   繁体   中英

Display text as it is entered

I have a simple <input type="text"> field in my html code with onChange property set to call javascript function, which takes the text and displays it. So, how it looks like currently:

<input type="text" id="inputField" onChange="displayText()"></input>    
<span id="toDisplay"></span>

and javascript:

function displayText() {
 var text = document.getElementById("inputField").value;
 document.getElementById("toDisplay").innerHTML = text;
}

So the text in the span is updated when the user presses enter.

Is there a way of doing a "real-time" update? In other words, I would like the text to appear in the span as soon as the user enters it.

<input type="text" id="inputField" onKeyUp="displayText()"></input> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM