- <!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>
- <title>javascript取得QueryString的方法</title>
- <script type="text/javascript">
- function GetQueryValue(searchUrl,queryStringName)
- {
- /**//*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- CopyRight: 网络有限公司 Joysos.Com
- Description: 在javascript内实现QueryString
- searchUrl: 查询字符串 document.location.search
- CreatDate: 2004-02-28
- AuthorName:: WuMeibo wumeibo@joysos.com
- LastUpdate:
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- var vStr="";
- if (searchUrl==null || searchUrl=="" || queryStringName==null || queryStringName=="") return vStr;
- //searchUrlsearchUrl = searchUrl.toLowerCase();
- //alert(searchUrl);
- queryStringName += "=";
- var itmp=searchUrl.indexOf(queryStringName);
- //alert(itmp);
- if (itmp<0){return vStr;}
- searchUrlsearchUrl = searchUrl.substr(itmp + queryStringName.length);
- //alert(searchUrl);
- itmp=searchUrl.indexOf("&");
- if (itmp<0)
- {
- return searchUrl;
- }
- else
- {
- searchUrlsearchUrl=searchUrl.substr(0,itmp);
- return searchUrl;
- }
- }
- function f(){
- var str = GetQueryValue("http://www.hello.com?id=1namename=tree","name");
- alert(str);
- }
- window.onload = function(){
- var url = document.location.search;//取得的是?id=1
- var str = GetQueryValue(url,"page");
- i1.value = str;
- }
- </script>
- </head>
- <body>
- <div>
- <input type="button" value="取得querystring" onclick="f();" /><br />
- 当前页面码是:<br />
- <input id="i1" type="text" />
- </div>
- </body>
- </html>
Javascript小知识(取得QueryString即地址栏中参数)
最新推荐文章于 2022-03-31 02:18:02 发布