首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

请教为什么用request获不了值

2012-02-04 
请问为什么用request获不了值?程序如下,文件名是gg.html,为什么访问http://localhost/gg.html?id45的时候

请问为什么用request获不了值?
程序如下,文件名是gg.html,为什么访问http://localhost/gg.html?id=45   的时候,没有打出45出来,反而说网页上有错误?

<html   >
<head>

<meta   name= "ContentType "   content= "text/html "   />
<meta   name= "CharSet "   content= "GB2312 "   />

<table>

<tr> <td   colspan= "4 "> <input     type= "button "   value= "drawline "   onclick= "javascript:drawCanvas() "/> </td> </tr>
</table>

<script   language= "javascript ">
var   ff=Request.QueryString[ "id "];

function   drawCanvas()
{

Response.Write(ff);

}
</script>

</head>
<body>

</body>
</html>


[解决办法]
<html>
<head>

<meta name= "ContentType " content= "text/html " />
<meta name= "CharSet " content= "GB2312 " />

<table>

<tr> <td colspan= "4 "> <input type= "button " value= "drawline " onclick= "javascript:drawCanvas() "/> </td> </tr>
</table>

<script language= "javascript ">
var ff=location.search;
ff=ff.substr(1,ff.length-1);
var paras = ff.split( "& ");
function getItem(id_name){
var a;
for(var i=0;i <paras.length;i++){
a = paras[i].split( "= ");
if(a[0]==id_name) return a[1];
}
return " ";
}
function drawCanvas()
{

document.write(getItem( "id "));

}
</script>

</head>
<body>

</body>
</html>

热点排行