静态HTML页面传递参数的方法
HTML页面如果要传递参数,其实原理就是利用javascript 读取地址栏的信息,从而得到参数值。
提交页面aa.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="GET" action="Untitled-1.htm">
Input Your Name: <input type="text" name="u">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
接收页面, bb.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT LANGUAGE="JavaScript">
<!--
// if uri parameter which is "?u=never-online.net&l=BlueDestiny";
// scripting by never-online
// blog.csdn.net/blueDestiny
var request = {
QueryString : function(val) {
var uri = window.location.search;
var re = new RegExp("" +val+ "=([^&?]*)", "ig");
return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
}
}
// so, You can using request.QueryString(para), like this
var u = request.QueryString("u");
var l = request.QueryString("l");
document.writeln("Hello! " + u);
//-->
</SCRIPT>
</head>
<body>
</body>
</html>
静态HTML页面传递参数的方法
最新推荐文章于 2024-08-03 17:05:14 发布