javascript | save textarea value with line breaks

旧城冷巷雨未停 提交于 2019-11-29 01:29:43
text = text.replace(/\n\r?/g, '<br />');

text is value from textarea.

lifetimes

The problem stems from the fact that line breaks (\n) are not the same as HTML <br /> tags.

Try this:

var text = document.forms[0].txt.value;
text = text.replace(/\n\r?/g, '<br />');

Edit, try this as the js:

var text = document.forms[0].txt.value;

if (text === true) { text = text.replace(/\n\r?/g, '<br />'); } 

var TestVar = new Array(i); 
var i = 0;
function save()
{
TestVar[i] = document.getElementById("text1").value + "/n" + document.getElementById("text2").value;
mydoc = document.open();
mydoc.write(TestVar);
mydoc.execCommand("saveAs",true,"TicketID.txt");
mydoc.close();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!