首页 > web前端 > js教程 > javascript获取URL参数与参数值的示例代码_javascript技巧

javascript获取URL参数与参数值的示例代码_javascript技巧

WBOY
发布: 2016-05-16 17:08:02
原创
982 人浏览过
复制代码 代码如下:

<script><BR>                  function goto_url(url){<BR>                     var new_url = "http://shop.usteel.com/index.php?app=list_release";<BR>                      var d_date = getParameter("date",url);<BR>                     if(d_date != '' ){<BR>                         new_url = "&" d_date;<BR>                    }<BR>                      var 物种 = getParameter("物种",url) ;<BR>                      if(物种 != ''){<BR>                         new_url = "&" 物种;<BR>                     }<br><br>                      window.open(new_url);<br><br>                   }<BR>                  //javascript获取指定参数及其对应的值  <BR>                  function getParameter(paraStr, url)  <BR>                  {  <BR>                      var result = "";  <BR>                      //获取URL中全部参数列表数据  <BR>                      var str = "&" url.split("?")[1];  <BR>                      var paraName = paraStr "=";  <BR>                      //判断要获取的参数是否存在  <BR>                      if(str.indexOf("&" paraName)!=-1)  <BR>                      {  <BR>                          //如果要获取的参数到结尾是否还包含“&”  <BR>                          if(str.substring(str.indexOf(paraName),str.length).indexOf("&")!=-1)  <BR>                          {  <BR>                              //得到要获取的参数到结尾的字符串  <BR>                              var TmpStr=str.substring(str.indexOf(paraName),str.length);  <BR>                              //截取从参数开始到最近的“&”出现位置间的字符  <BR>                              result=TmpStr.substr(TmpStr.indexOf(paraName),TmpStr.indexOf("&")-TmpStr.indexOf(paraName));    <BR>                          }  <BR>                          else  <BR>                          {    <BR>                              result=str.substring(str.indexOf(paraName),str.length);    <BR>                          }  <BR>                      }    <BR>                      else  <BR>                      {    <BR>                          result="";    <BR>                      }    <BR>                      return (result.replace("&",""));    <BR>                  }  <BR>                  </script>

下面例子很完整 经测试
复制代码 代码如下:

 
     
     
     
    javascript获取URL参数和参数值 
     
   
 

     
     
   
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板