李沧八马茶业:javascript

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 00:01:24
请问在javascript 中有相当于ASP的Request.querystring用来在另一个页面中获取提交表格内容的代码吗?

可以的,但表单必须用method="get"来定义,也就是最终访问页面要用xxx.htm?id=1这种形式,而不能用method="post"来隐式传递,这样就提取不到了,示例如下:

<script language="javascript">
var pos,str,para,parastr,tempstr1;
tempstr="";
str = window.location.href;
pos = str.indexOf("?")
parastr = str.substring(pos+1);
document.write("<br>文件路径:"+str);
if (pos>0){
document.write("<br>所有参数:"+parastr);
}
else
{
document.write ("无参数");
}

if (str.indexOf("&")>0){
para = parastr.split("&");
for(i=0;i<para.length;i++)
{
tempstr1 = para[i];

pos = tempstr1.indexOf("=");
//document.write (tempstr1.substring(0,pos));
document.write ("<br>参数"+i+":"+tempstr1.substring(0,pos));
document.write ("等于:"+tempstr1.substring(pos+1));
}
}
</script>

有,但是javascript必须为服务器语句,和ASP一样