• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
让理想赞美生活
Tiehui.Lu 的代码库
博客园    首页    新随笔    联系   管理    订阅  订阅
纯JS 得到GET方式传递过来的参数
纯JS 得到GET方式传递过来的参数 代码介绍:纯JS得到GET方式的好处在于:可以将html代码和服务器代码很好的分离开。 对于习惯:html+js+xml+php(c#,jsp)风格架构系统特别好! 基本思想:用location.href得到当前链接,再拆分得到需要的参数值。 奇妙之处:习惯性的链接为:index.html?a=1,此处认为1为所需要的值。现在:index.html?1,我们可以直接得到所需要的值“1”

代码介绍:纯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>
posted on 2008-03-26 11:56  Tiehui.Lu  阅读(3797)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3