javascript Replacing \n with <br> inside createTextNode
问题 I have a String with \n - line breaks in Javascript, that I want to replace for another text using createTextNode() in Javascript. <script type="text/javascript"> function changeText() { var Explanation="Test\n Test2"; var parent3 = document.getElementById("The_Explanation"); parent3.innerHTML=''; var myP3 = document.createElement("p"); var myText3 = document.createTextNode(""+Explanation); myP3.appendChild(myText3); parent3.appendChild(myP3); } </script> All tries to get the line break into