您的位置:首页 > Web前端 > HTML

不同web如何通讯之 html页面获取传递的参数

2007-07-30 15:26 621 查看
有时候在项目开发过程中,因为要进行数据传递,或者进行重定向。如果是使用同一个平台,比如jsp,或者asp,那么文件非常好解决,但是我们在开发过程中,特别是具体接口功能的页面,就无法规定使用何种语言,

所有可以是用html进行转换,那么如何获取传递的参数,看下面的js。

<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 ("无参数");
}

// 文件路径:hello.html?a=1&b=2&c=3
// 所有参数:a=1&b=2&c=3
// 参数0:a等于:1
// 参数1:b等于:2
// 参数2:c等于:3

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>

未完,代完善
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: