使用 Request.QueryString() 获取变量值时出现未定义错误
我使用以下代码打开一个弹出窗口并传递 ID 作为查询字符串。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript" type="text/javascript">
function openwindow(divID) {
window.open("pp.html?id="+divID+"","","status=yes, location=yes, width=700, height=400");
}
</script>
</head>
<body>
<a href="#" onclick="openwindow('one')" id="one">One</a>
<br />
<a href="#" onclick="openwindow('two')" id="two">Two</a>
<br />
<a href="#" onclick="openwindow('three')" id="three">Three</a>
</body>
</html>
场景是,我需要在弹出窗口中显示 id 与查询字符串值相似的 DIV。弹出窗口代码是
<html>
<head>
<script language="javascript" type="text/javascript">
function getid() {
if (Request.QueryString("id")!=null)
var id = Request.QueryString("id");
document.getElementById(id).style.display = "block";
}
</script>
</head>
<body onload="getid();">
<div style=" overflow:hidden">
<div style="margin-left:-5px;"><input type="file" style="" /></div>
</div>
<div style="width:200px; height:200px; border:1px solid #999999; background- color:#CCCCCC; display:none" id="one">Hello! ONE</div>
<div style="width:200px; height:200px; border:1px solid #999999; background-color:#CCCCCC; display:none" id="two">Hello! TWO</div>
<div style="width:200px; height:200px; border:1px solid #999999; background-color:#CCCCCC; display:none" id="three">Hello! THREE</div>
</body>
</html>
现在,弹出窗口给出错误“请求未定义”。
I am using the following code to open a popup window and passing the ID of as query string.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript" type="text/javascript">
function openwindow(divID) {
window.open("pp.html?id="+divID+"","","status=yes, location=yes, width=700, height=400");
}
</script>
</head>
<body>
<a href="#" onclick="openwindow('one')" id="one">One</a>
<br />
<a href="#" onclick="openwindow('two')" id="two">Two</a>
<br />
<a href="#" onclick="openwindow('three')" id="three">Three</a>
</body>
</html>
The scenario is, i need to show the DIV in popup window whose id is similar to querystring value. Popup window code is
<html>
<head>
<script language="javascript" type="text/javascript">
function getid() {
if (Request.QueryString("id")!=null)
var id = Request.QueryString("id");
document.getElementById(id).style.display = "block";
}
</script>
</head>
<body onload="getid();">
<div style=" overflow:hidden">
<div style="margin-left:-5px;"><input type="file" style="" /></div>
</div>
<div style="width:200px; height:200px; border:1px solid #999999; background- color:#CCCCCC; display:none" id="one">Hello! ONE</div>
<div style="width:200px; height:200px; border:1px solid #999999; background-color:#CCCCCC; display:none" id="two">Hello! TWO</div>
<div style="width:200px; height:200px; border:1px solid #999999; background-color:#CCCCCC; display:none" id="three">Hello! THREE</div>
</body>
</html>
Now, Popup window is giving error "Request is undefined".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将 ASP.NET 服务器端语言与 javascript 混合在一起,这当然是不可能的。尝试这样:
如果您没有使用服务器端语言,您可以使用以下函数读取 javascript 中的查询字符串参数(取自此处):
并像这样使用:
You are mixing ASP.NET server side language with javascript which of course is not possible. Try like this:
If you are not using a server side language you could use the following function to read query string parameters in javascript (taken from here):
And use like this: