我想輸出一個文本文件的行到HTA中的div。文本本身出現的很好,但是這些文字並沒有結束。相反,文本在一條大線上組合在一起。如果我打印到msgbox,它會顯示正確的分隔線。多行文本文件輸出html
function updateTPtally()
{
var fso, appdir, messagefile, ts, messagetext, line;
fso = new ActiveXObject("Scripting.FileSystemObject");
if (MESSAGE_FILE_NAME7.indexOf("\\") == -1) {
appdir = unescape(fso.GetParentFolderName(location.pathname));
messagefile = fso.BuildPath(appdir, MESSAGE_FILE_NAME7);
} else {
messagefile = MESSAGE_FILE_NAME7;
}
try {
// Open the message-of-the-day file as a TextStream.
ts = fso.OpenTextFile(messagefile, 1);
messagetext = "";
while (! ts.AtEndOfStream) {
line = ts.ReadLine();
// If the line contains text, enclose in <p> element;
// otherwise, construct a blank line with a nonbreaking space.
if (line.length > 0)
line = line.replace(/^(.*)$/, "$1");
else
line = "<p> </p>";
messagetext += line;
}
ts.Close();
}
// Construct an error message if an error occurred.
catch(err) {
messagetext = "<p>Can't display the message of the day.</p>"
+ "<p> </p>"
+ "<p>Error <b>0x" + hex(err.number) + "</b><br />"
+ err.description + "</p>";
}
// Update the innerHTML element of the textarea element with the
document.getElementById("TPtallymemo").innerHTML = messagetext;
}
編輯: 我已經加入 線= line.replace(/ \ N/G, 「
」);
這似乎工作,但文本的第一個字。這是我的文本文件:
Hello.
This should be line two. And written all in one line.
This should be line three, and also written on one line.
這是在我的跨度打印出:
Hello.
This
should be line two. And written all in one line.
This
should be line three, and also written on one line.
在Windows中,換行符是'\ r \ n'。你應該替換它而不是'\ n'。 – Teemu