代码介绍:纯JS得到GET方式的好处在于:可以将html代码和服务器代码很好的分离开。
对于习惯:html+js+xml+php(c#,jsp)风格架构系统特别好!
基本思想:用location.href得到当前链接,再拆分得到需要的参数值。
奇妙之处:习惯性的链接为:index.html?a=1,此处认为1为所需要的值。
现在:index.html?1,我们可以直接得到所需要的值“1”
1.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>1</title>
</head>
<body>
<form name="r" method="get" action="2.html">
<input type="text" name="i" id="i" value="t" />
<input type="submit" value="sumbit" />
</form>
</body>
</html>2.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>2</title>
</head>
<body>
<script type="text/javascript">
var currHref = location.href;
var index = currHref.lastIndexOf("?");
var param = "";
if(index != "-1"){ param = currHref.substr(index+1);}
alert(param);
</script>
</body>
</html>



浙公网安备 33010602011771号