Preserve newlines when setting html in a div from a textarea - Jquery

前端 未结 1 843
时光取名叫无心
时光取名叫无心 2021-01-28 09:37

I got this little html -:

相关标签:
1条回答
  • 2021-01-28 10:14

    The new lines are preserved, but not converted to HTML new lines (<BR/>), so they are ignored.

    You can convert them to <BR/> with .replace:

    $("#copyToDiv").on("click",function(){ $("#viewOne").html( $("#viewTwo").val().replace("\n","<br/>") ) });
    
    0 讨论(0)
提交回复
热议问题