我有这个代码:
<%If CInt(Request.QueryString("OpenYouthHistory")) > 0 Then %>
<script>
var yid = <% Request.QueryString("OpenYouthHistory") %>;
window.open("YouthHistory.asp?YouthID=" + yid);
</script>
<% End If %>
如果设置了OpenYouthHistory
查询字符串变量,我想在弹出窗口中打开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 %>