Space 在两个 ASP 表达式代码之间被删除

Space being removed between two ASP expression codes

我是 ASP 的新手,受客户委托更新文件。当我尝试 "echo" 两个带有 space 的变量时,space 被删除。有什么想法吗?

这里有两个例子:

<%
    Dim variable1, variable2
    variable1 = "Hello"
    variable2 = "there"
%>
<p><%= variable1 %> <%= variable2 %></p>

<p><% Response.write( variable1 ) %> <%= Response.write( variable2 ) %></p>

这写:<p>Hellothere</p> 两个词之间没有 space。难道我做错了什么?或者这对 ASP 来说是正常的吗?

我已经使用了以下内容,但我很难相信 <% %> 之外的内容会被删除。

<% Response.Write( variable1 & " " & variable2 ) %>

如有任何帮助,我们将不胜感激。

是的。这是其中之一。代码块 (<%...%>) 之前或之后的空白被认为是 HTML 文档的一部分,但 连续代码块之间的空白被忽略。您有几个选择:

  1. 在(显式空格)之间插入 &nbsp;

    <p><%= variable1 %>&nbsp;<%= variable2 %></p>
    
  2. 在单个 ASP 上下文中写入完整标记:

    Response.Write "<p>" & variable1 & " " & variable2 & "</p>"
    ' or
    <p><%= variable1 & " " & variable2 %></p>