简体   繁体   中英

How to add New line to a div contenteditable in javascript?

Basically I'm using a div with contenteditable as a text box. Now when I input a newline (By pressing enter) it doesn't counts it and escaps it.

Jsfiddle: https://jsfiddle.net/pgsp7q57/3/

You can input:

Hello
How are you

And see the result by yourself which is( hellohow are you ) But I need to get the result as:

Hello
How are you

All replies are much appreciated.

Try this code .

var hello = "hello<br>how\nare\nyou";
document.getElementById("hey").innerHTML = hello;

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