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

纯HTML页面之间传递参数

2011-03-30 15:49 288 查看
<html>

<head>

<meta http-equiv="Content-Type" content="html/text; charset=utf-8"/>

<title>JS get Parameter</title>

<script src="resource/js/param.js" type="text/javascript"></script>

</head>

<body>

<table>

<tr>

<td><input type="text" name="user" /></td>

<td><input type="text" name="password" /></td>

<td><input type="text" name="sysno" /></td>

</tr>

</table>

</body>

<script type="text/javascript">

var LocString=String(window.document.location.href);

function getQueryStr(str){

var rs = new RegExp("(^|)"+str+"=([^/&]*)(/&|$)","gi").exec(LocString), tmp;

if(tmp=rs){

return tmp[2];

}

// parameter cannot be found

return "";

}

document.getElementById("user").value = getQueryStr("user");

document.getElementById("password").value = getQueryStr("password");

document.getElementById("sysno").value = getQueryStr("sysno");

</script>

</html>

<html>
<head>
<meta http-equiv="Content-Type" content="html/text; charset=utf-8"/>
<title>JS get Parameter</title>
<script src="resource/js/param.js" type="text/javascript"></script>
</head>
<body>
<table>
<tr>
<td><input type="text" name="user" /></td>
<td><input type="text" name="password" /></td>
<td><input type="text" name="sysno" /></td>
</tr>
</table>
</body>
<script type="text/javascript">
var LocString=String(window.document.location.href);

function getQueryStr(str){
var rs = new RegExp("(^|)"+str+"=([^/&]*)(/&|$)","gi").exec(LocString), tmp;

if(tmp=rs){
return tmp[2];
}

// parameter cannot be found
return "";
}

document.getElementById("user").value = getQueryStr("user");
document.getElementById("password").value = getQueryStr("password");
document.getElementById("sysno").value = getQueryStr("sysno");
</script>
</html>

通过test.html?user=abc&password=123&sysno=001的测试结果来看,截获参数的目的达到了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: