经典 ASP 查询字符串变量已设置和未设置

Classic ASP query string variable is both set and unset

我有这个代码:

<%If CInt(Request.QueryString("OpenYouthHistory")) > 0 Then %>
<script>
    var yid = <% Request.QueryString("OpenYouthHistory") %>;
    window.open("YouthHistory.asp?YouthID=" + yid);
</script>
<% End If %>

如果设置了 OpenYouthHistory 查询字符串变量,我想在 window 弹出窗口中打开 YouthHistory.asp 页面。但是,当我 运行 它的值为 210 时,我得到以下输出:

<script>
    var yid = ;
    window.open("YouthHistory.asp?YouthID=" + yid);
</script>

这当然是无效的JavaScript。但是为什么 yid 变量没有得到值呢?如果查询字符串变量真的是空的,为什么 <script> 标签甚至呈现?我很困惑...

使用 <%= 这是 <% Response.Write

的快捷方式
<%If CInt(Request.QueryString("OpenYouthHistory")) > 0 Then %>
<script>
    var yid = <%=Request.QueryString("OpenYouthHistory") %>;
    window.open("YouthHistory.asp?YouthID=" + yid);
</script>
<% End If %>