对于web项目中一些参数通常都是拼接在url后面,在jsp中有request.getParameter("key")进行获取,在js中也可进行获取。
目标页面,进行参数接收的页面:
内容简单就直接贴例子了,(ps:map这个js函数在上一篇博客中有介绍)
进行跳转的页面:
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>redirect</title>
- </head>
- <body>
- <a href="search.html?name=akwolf&age=22">to a new page</a>
- </body>
- </html>
目标页面,进行参数接收的页面:
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <script type="text/javascript" src="../jslib/jquery-1.5.min.js"></script>
- <script type="text/javascript" src="../jslib/map.js"></script>
- <script type="text/javascript">
- var map = new Map() ;
- $(function(){
- var info = $("#info") ;
- var param = window.location.search ;
- paramparam = param.substring(1) ;
- paramparams = param.split("&") ;
- $.each(params,function(){
- //var curr = this ;
- var m = this.split("=") ;
- map.put(m[0],m[1]) ;
- }) ;
- }) ;
- function showMsg(){
- alert(map.toString());
- }
- </script>
- <title>search</title>
- </head>
- <body>
- <div id="info"></div>
- <input type="button" value="toStr" onclick="showMsg()"/>
- </body>
- </html>