Show newlines in html textarea

前端 未结 3 1631
遥遥无期
遥遥无期 2020-12-04 04:01

I have a textarea and I set its text to a string with \\n in it. I would expect that to represent a line break.

$(\"#ConfirmEmailText\").text(\         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 04:37

    Did you try?

       text = text.replace(/(\r\n|\r|\n)/g, '\n');
    

    Or use the DOM structure's .nodeValue property.

    EDIT : i may have not been clear. Instead of using innerHTML to set the text try using nodeValue

提交回复
热议问题