转义 asp/vbscript 脚本标签
Escape asp/vbscript script tags
如何转义asp指令输出
所以我需要使用 asp 标签打印到页面字符串
<%
response.write "<%=Count%>"
%>
但是我得到错误
Microsoft VBScript compilation error '800a0409'
Unterminated string constant
那么如何打印脚本标签呢?
所以我需要 <%=Count%>
而不是 Count
有什么方法可以代替?
<%
response.write "<" & "%=Count%" & ">"
%>
方法是在代码块中使用 <script>
标签而不是 <% ... %>
:
<script language="vbscript" runat="server">
Response.Write "<%= Count %>"
</script>
输出:
<%= Count %>
您只需要确保在尝试使用 Response.Write()
像这样的东西之前 HTML 进行编码;
这里我使用 %
的 HTML 编码值 %
来阻止 VBScript 运行-time 吐出它的虚拟 (但你甚至可以使用 <
代表 <
和 >
代表 >
的任何东西,正如建议的那样).
<%
Response.Write "<%=Count%>"
%>
输出:
<%=Count%>
或者,您可以通过 shorthand Response.Write
:
简单地使用 <
和 >
字符代码
<%= "<%= Count %>" %>
如何转义asp指令输出
所以我需要使用 asp 标签打印到页面字符串
<%
response.write "<%=Count%>"
%>
但是我得到错误
Microsoft VBScript compilation error '800a0409' Unterminated string constant
那么如何打印脚本标签呢?
所以我需要 <%=Count%>
而不是 Count
有什么方法可以代替?
<%
response.write "<" & "%=Count%" & ">"
%>
方法是在代码块中使用 <script>
标签而不是 <% ... %>
:
<script language="vbscript" runat="server">
Response.Write "<%= Count %>"
</script>
输出:
<%= Count %>
您只需要确保在尝试使用 Response.Write()
像这样的东西之前 HTML 进行编码;
这里我使用 %
的 HTML 编码值 %
来阻止 VBScript 运行-time 吐出它的虚拟 (但你甚至可以使用 <
代表 <
和 >
代表 >
的任何东西,正如建议的那样).
<%
Response.Write "<%=Count%>"
%>
输出:
<%=Count%>
或者,您可以通过 shorthand Response.Write
:
<
和 >
字符代码
<%= "<%= Count %>" %>