1

当我使用当前脚本加载一些 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> 
4

1 回答 1

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 上使用验证器(整洁,...))

更新:

证据:

证据

于 2012-11-29T12:13:53.470 回答