当我用当前脚本加载一些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>
答案 0 :(得分:2)
如果您在问题上使用集中的.hta,例如
<html>
<head>
<hta:application id="t"></hta>
<title>t</title>
<script language="vbscript">
Sub ol()
MsgBox "ol"
a = Array("line1", "line2")
document.all.ta1.value = Join(a, vbCrLf)
document.all.ta2.innerHTML = Join(a, vbCrLf)
End Sub
</script>
</head>
<body onload="ol">
<textarea id="ta1" rows="4" cols="88"></textarea>
<textarea id="ta2" rows="4" cols="88"></textarea>
</body>
</html>
您一眼就能看到问题是由于使用.innerHTML
代替.value
造成的。
(顺便说一下:你应该在你的.html上使用验证器(整理,......))
<强>更新强>
证据: