【问题标题】:I have a text area, that will have multiple lines of text我有一个文本区域,它将有多行文本
【发布时间】:2017-04-04 21:24:19
【问题描述】:

我有一个文本区域,它将包含多行文本,并且我需要在输入文本区域时保留所有格式的输出。如何才能做到这一点?以下是我创建文本区域的方式:

<table border="0" cellpadding="5" cellspacing="5" width="95%">              
<tr>
<td colspan="2">
<b>Status: </b> 
<textarea name="Text2" id="styled"></textarea>
</td>
</tr>
</table>

【问题讨论】:

  • 什么输出?什么格式?
  • 我正在使用输入到该文本区域的文本来为我使用 CDO.Message 发送的电子邮件创建文本输出。

标签: vbscript hta


【解决方案1】:

无法按照您的要求保持&lt;textarea&gt; 中文本的格式。

如果文本中存在一些新行,您可以实现维护新行(基本上是文本被换行)。 您必须使用“wrap=Hard”。

https://www.w3schools.com/tags/att_textarea_wrap.asp

另请参阅 stackoverflow 答案,其中有更多关于在 &lt;textarea&gt; 中保留文本格式的解释(也可以查看 cmets)

HTML : How to retain formatting in textarea?

how to preserve formatting of html textarea

【讨论】:

  • 最重要的部分就是维护换行符。
【解决方案2】:

我能够通过将文本区域导出到文本文件,附加数据,然后将其导入回使用来弄清楚如何做到这一点 fso.OpenTextFile("C:\file.txt",ForReading).ReadAll 并使用格式化 (html正文前) 这样做我能够保持我的换行符,然后我使用 CDO.Message 发送信息。

Const FOR_APPENDING = 8 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTSO = objFSO.OpenTextFile("C:File.txt", FOR_APPENDING)   
objTSO.WriteLine strDT & ":" & vbCrLf & Text2.value & vbCrLf
objTSO.Close()



Sub SendEmail(strSubject, strBody, strBody8, strFrom)

Const ForReading = 1
Dim fso, BodyText
Set fso = CreateObject("Scripting.FileSystemObject")

strMailbox = "Address<Email@email.com>"                                     
' E-Mail address being sent to
strSMTPServer = "SMTP Server"                                           
' Primary SMTP relay server name    
strSMTPPort = 25                                                            
' SMTP Port Number

Set objEmail = CreateObject( "CDO.Message" )
BodyText = fso.OpenTextFile("C:\file.txt",ForReading).ReadAll
With objEmail
.From     = strFrom
.To       = strMailbox
.Subject  = strSubject
.HTMLBody = "<html><body><pre>" & strBody & "<BR>" & BodyText & "<BR>" & 
 strBody8 & "</pre></body></html>"

With .Configuration.Fields
.Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"      ) = 2
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"     ) = 
strSMTPServer
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = 
strSMTPPort
.Update
End With
.Send                                               ' Send the message!
End With
Set objEmail = Nothing

【讨论】:

    猜你喜欢
    • 2012-02-09
    • 1970-01-01
    • 2016-11-16
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多