我想输出一个文本文件的行到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