Show newlines in html textarea

前端 未结 3 1621
遥遥无期
遥遥无期 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:21

    try

    text = text.replace("\n","<br/>");
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-04 04:46

    Set the value not the innerText;

    $("#ConfirmEmailText").val("test\n\ntest\ntest");
    
    0 讨论(0)
提交回复
热议问题