将 HTML 片段放入 ASP 变量问题

Placing HTML snippet inside of ASP variable issues

我有一个用 VBScript 编码的经典 ASP 网页。我有一个按钮的 HTML 代码,如果某个变量是 True,我只想显示它。我遇到的问题是找到正确的语法来将 HTML 代码放在变量中,因为按钮代码本身有一段 VBScript,它确定按钮 link 通向的位置。

这是我的代码示例以及我要完成的工作:

yesNo= False
button= "<div class="view">
              <a href="<%=theImaFir4%>">  <!--The ASP here determines the link and is absolutely necessary-->
                   <button class="btn"type="button">View</button>
              </a>
        </div>"

这符合我的要求:

If Not theImaFir4="#" Then 'default value of link is #'
yesNo= True

If yesNo= True Then
Response.write(button)

关于如何将我的 HTML 和 ASP 代码正确放置在我的按钮变量中有什么想法吗?按照我的方式进行操作,HTML 片段中的 %> 标记关闭了我的其余 ASP 代码。

我已尽力解释我要完成的工作,但如果您需要更多信息,请告诉我。

您不必打开新的 asp 标签。您还需要确保转义按钮文本中的双引号。

button= "<div class=""view"">
          <a href=""" & theImaFir4 & """>  
               <button class=""btn"" type=""button"">View</button>
          </a>
    </div>"

让自己的生活更轻松,对 HTML 属性值使用单引号。那么你就不用担心在VBScript中需要转义双引号了。

此外,VBScript 将行尾标记解释为语句的结尾,因此如果不使用行继续 (_) 和连接 ( &) 运算符。

例如:

button = "<div class='view'>" _
         & "<a href='" & theImaFir4 & "'>" _
         & "<button class='btn' type='button'>View</button>" _
         & "</a>" _
         & "</div>"

此处也不需要 <%= %>,因为如果您正在编写 VBScript,您已经在 ASP 代码标记中。只需将您的变量连接到您的字符串中:

"<a href='" & theImaFir4 & "'>"

连同其他答案,我还要补充一点,使用 <%=theImaFir4%> 仅供内联 html 使用,因为它会触发 Response.Write 事件。

当你已经在括号内时<% %>你不用等号来显示html因为你还没到。但是您可以在 html 中使用 <%=button%>