我有一段代码,它将多个
我有一段代码,它将多个
text = text.replace(/\n\r?/g, '<br />');
文本是来自文本区域的值。
问题的根源在于换行符 (\n
) 与 HTML 中的 <br />
标签不同。
尝试这样做:
var text = document.forms[0].txt.value;
text = text.replace(/\n\r?/g, '<br />');
编辑,尝试使用以下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();
}