简体   繁体   中英

How to push a line of text down in a textarea box?

Let's just say I have this function( function() not shown):

document.getElementById("chatDisplay").value= document.getElementById("chatDisplay").value + userName + ":" + document.getElementById("textBox").value

what I want to do is between chatDisplay (within) the .value= and the userName is too push that line of code down(similar to a <br> ).Is there anyway to get that done?

Use \\n . It works exactly as <br> but it is used for text. It means new line

...."chatDisplay").value + "\n" + userName....

Use &#10; Line Feed and &#13; Carriage Return instead of <br/> :

 <textarea cols='60' rows='8'>Hello.&#13;&#10;World&#13;&#10;&#13;&#10;How are you?</textarea> 

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