当我使用当前脚本加载一些 csv 文件时。Textarea 没有像 csv 格式那样呈现正确的格式:
1.csv:
text1
text2
现在 1.csv 输出:
text1 text2
预期的 1.csv 输出:
text1
text2
实际上 textarea 无法为我创建一些未知的换行符。
剧本:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<hta:application
applicationname="MyHTA"
border="thick"
borderstyle="normal"
caption="My HTML Application"
contextmenu="no"
icon="myicon.ico"
maximizebutton="no"
minimizebutton="yes"
navigable="no"
scroll="yes"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="1.0"
windowstate="normal"
>
<script language="vbscript">
Sub RunCommonDialog
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "CSV Files (*.csv)|*.csv|All Files|*.*"
objDialog.InitialDir = "C:\Documents and Settings\All Users\Desktop"
intResult = objDialog.ShowOpen
If intResult = 0 Then
Exit Sub
Else
CommonDialog.value = objDialog.FileName
CommonDialog_Span.innerHTML = objDialog.FileName
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(objDialog.FileName, ForReading)
contents = objTextFile.ReadAll
objTextFile.Close
Set objFSO = Nothing
Set objReadFile = Nothing
PRE.innerHTML = contents
End If
End Sub
Sub reloadHTA()
location.reload True
End Sub
</script>
<body>
<input type="hidden" id="CommonDialog"><input type="button" onclick="RunCommonDialog" value="Browse..."><input class = "StdBtt Meta" type = "BUTTON" value = "Reset" onclick = "reloadHTA"><br>
<p>File: <span id="CommonDialog_Span"></span></p>
<textarea rows="4" cols="88" name="PRE" readonly="readonly">
</textarea>
</body>