Vbscript 如何在经典asp中将文本分隔为列表

Vbscript 如何在经典asp中将文本分隔为列表,vbscript,asp-classic,Vbscript,Asp Classic,我有一个问题,我需要弄清楚如何分割在文本区域中输入的文本,但在键入的时候只是视觉顺序,我将详细解释它 一个确定的用户在文本区域中键入如下内容 这就是输入的样子 这就是用户在文本框中的输入方式,但当我显示它时,它看起来是这样的(请注意,并非所有用户都以点结束书写) 如何直观地将它们分开并显示为列表?我尝试了replace、mid和其他功能,但没有起作用,这要提前感谢试试这个,在换行符处拆分文本并在数组上循环以创建列表: 函数addText(){ let list=document.querySe

我有一个问题,我需要弄清楚如何分割在文本区域中输入的文本,但在键入的时候只是视觉顺序,我将详细解释它

一个确定的用户在文本区域中键入如下内容

这就是输入的样子

这就是用户在文本框中的输入方式,但当我显示它时,它看起来是这样的(请注意,并非所有用户都以点结束书写)


如何直观地将它们分开并显示为列表?我尝试了replace、mid和其他功能,但没有起作用,这要提前感谢

试试这个,在换行符处拆分文本并在数组上循环以创建列表:

函数addText(){
let list=document.querySelector(“#list”);
让text=document.querySelector('#text').value;
让值=text.split('\n');
让listFragment=new DocumentFragment();
values.forEach(值=>{
设span=document.createElement('span');
span.textContent=值+'';
追加(span);
});
追加(listFragment);
}

进入

因为HTML忽略空白,所以您不会看到换行符,但您可以通过查看浏览器页面源代码来确认它们是否存在

例如,如果您想将文本作为无序列表输出(
),您可以这样做

<%
Option Explicit

'Starting point for the script.
Call init_page()

Sub init_page()
  Dim issubmit: issubmit = (Request.Form.Count > 0)
  Dim value: value = Request.Form("sampletext") & ""

  Call build_form(value)
  If issubmit Then
    Call Response.Write(build_list(value))
  End If
End Sub

Sub build_form(value)
%>
<form method="POST">
  <textarea name="sampletext" rows="5"><%= value %></textarea>
  <button>Submit</button>
</form>
<%
End Sub

Function build_list(value)
  Dim html, list, item, items
  If Len(value) < 1 Then build_list = ""
  list = Split(value, vbNewLine)
  If IsArray(list) Then
    html = "<ul>"
    items = UBound(list)
    For item = 0 To items
      html = html & "<li>" & list(item) & "</li>"
    Next
    html = html & "</ul>"
  Else
    html = "Error: List was not in the correct format"
  End If
  build_list = html
End Function
%>

如果您只想显示它,而不需要太多额外的麻烦,您可以在一行代码中使用
replace()

replace(inputFieldString, vbCrlf, '<br>')
替换(inputFieldString,vbCrlf,

我们的一些旧系统使用此方法处理来自textarea输入的内容。快速简单。

这能回答您的问题吗?换行符仍然存在,它只是在呈现HTML时没有影响(如果您检查页面源代码,您可能会看到单独的行),因此使用
lines=Spilt(sampletext,vbNewLine)
lines
变量设置为
Array
,您可以迭代并生成
(无序列表)。在经典ASP环境中,在客户端执行此操作毫无意义,如果您可能正在构建SPA的话。dup目标涵盖了这一点-
<%
Option Explicit

'Starting point for the script.
Call init_page()

Sub init_page()
  Dim issubmit: issubmit = (Request.Form.Count > 0)
  Dim value: value = Request.Form("sampletext") & ""

  Call build_form(value)
  If issubmit Then
    Call Response.Write(build_list(value))
  End If
End Sub

Sub build_form(value)
%>
<form method="POST">
  <textarea name="sampletext" rows="5"><%= value %></textarea>
  <button>Submit</button>
</form>
<%
End Sub

Function build_list(value)
  Dim html, list, item, items
  If Len(value) < 1 Then build_list = ""
  list = Split(value, vbNewLine)
  If IsArray(list) Then
    html = "<ul>"
    items = UBound(list)
    For item = 0 To items
      html = html & "<li>" & list(item) & "</li>"
    Next
    html = html & "</ul>"
  Else
    html = "Error: List was not in the correct format"
  End If
  build_list = html
End Function
%>
replace(inputFieldString, vbCrlf, '<br>')