隨筆-3  評論-26  文章-41  trackbacks-0
          /*
          獲取URL中最后一項參數的值
          */


          var str=window.location.href;
          //alert(str);
          var es=/SouceID=/
          es.exec(str); 
          var right=RegExp.rightContext; 
          //alert(right);
             
            //列子
              <script language="javascript"> 
              var str=window.location.href; 
              var es=/SouceID=/; 
              es.exec(str); 
              var right=RegExp.rightContext; 
              //alert(right);
              switch(right){
              case 'Din':
              case 'Exh':
              case 'Banks':
              case 'Shop':
              case 'Treat':
              case 'Trip':
                   ChgTab('tab3','tabcontent3');
                   break;
              case 'Air':
              case 'Railway':
              case 'Road':
              case 'Subway':
                    ChgTab('tab2','tabcontent2');
                    break;
             default:
                   ChgTab('tab1','tabcontent1');
          }
          </script>


          //以下是函數的寫法
          function GetParam(){
              
          var url = document.location.href;
              
          var name=""
              
          if (url.indexOf("=")>0)
              
          {
                  name 
          = url.substring(url.indexOf("=")+1,url.length)
              }

              
          return name;
          }



          /*
          獲取指定的URL參數值
          URL:http://www.aygfsteel.com/blog?name=bainian
          參數:paramName URL參數
          調用方法:getParam("name")
          返回值:bainian
          */

          //1.
          function getParam(paramName)
          {
                  paramValue 
          = "";
                  isFound 
          = false;
                  
          if (this.location.search.indexOf("?"== 0 && this.location.search.indexOf("=")>1)
                  
          {
                      arrSource 
          = unescape(this.location.search).substring(1,this.location.search.length).split("&");
                      i 
          = 0;
                      
          while (i < arrSource.length && !isFound)
                      
          {
                          
          if (arrSource[i].indexOf("="> 0)
                          
          {
                               
          if (arrSource[i].split("=")[0].toLowerCase()==paramName.toLowerCase())
                               
          {
                                  paramValue 
          = arrSource[i].split("=")[1];
                                  isFound 
          = true;
                               }

                          }

                          i
          ++;
                      }
             
                  }

             
          return paramValue;
          }



          //2.
          function Request(sName)
          {

            
          /*
             get last loc. of ?
             right: find first loc. of sName
             +2
             retrieve value before next &
            
            
          */

            
            
          var sURL = new String(window.location);
            
          var sURL = document.location.href;
            
          var iQMark= sURL.lastIndexOf('?');
            
          var iLensName=sName.length;
            
            
          //retrieve loc. of sName
            var iStart = sURL.indexOf('?+ sName +'=') //limitation 1
            if (iStart==-1)
                  
          {//not found at start
                  iStart = sURL.indexOf('&+ sName +'=')//limitation 1
                          if (iStart==-1)
                             
          {//not found at end
                              return 0//not found
                             }
             
                  }

                  
            iStart 
          = iStart + + iLensName + 2;
            
          var iTemp= sURL.indexOf('&',iStart); //next pair start
            if (iTemp ==-1)
                          
          {//EOF
                          iTemp=sURL.length;
                          }
            
            
          return sURL.slice(iStart,iTemp ) ;
            sURL
          =null;//destroy String
          }
          posted on 2008-03-12 12:53 百年 閱讀(37317) 評論(5)  編輯  收藏 所屬分類: Javascript Article

          評論:
          # re: js獲取URL中的參數值[未登錄] 2012-10-09 23:04 | lee
          獲取url中的參數值  回復  更多評論
            
          # re: js獲取URL中的參數值[未登錄] 2013-02-09 08:43 | 匿名
          感謝分享.  回復  更多評論
            
          # re: js獲取URL中的參數值 2013-08-06 10:58 | afasfas
          feafwaefeawfewaef  回復  更多評論
            
          # re: js獲取URL中的參數值 2013-08-06 10:58 | afasfas
          @afasfas
          @afasfas
            回復  更多評論
            
          # re: js獲取URL中的參數值 2014-08-26 14:11 | 趙元春
          網址打不開  回復  更多評論
            
          <2012年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          CSS

          Draw dynamicdrive

          Draw Flash

          Fade

          Flash+XML

          • Flash+XML
          • http://www.flashcom.com.cn/bbs/forumdisplay.php?f=3

          Jacob

          Search Website

          Struts

          Studying English

          Text Link

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 张家界市| 肃北| 青岛市| 韶山市| 汉阴县| 永定县| 连南| 全州县| 武宁县| 尚义县| 博湖县| 公安县| 宝坻区| 新巴尔虎右旗| 颍上县| 诏安县| 分宜县| 石阡县| 卢湾区| 深圳市| 富平县| 哈尔滨市| 南城县| 汉川市| 津市市| 林甸县| 房山区| 彭水| 云林县| 保山市| 玉树县| 镇雄县| 平江县| 元江| 松潘县| 隆回县| 八宿县| 合山市| 新安县| 吉木萨尔县| 乌兰县|