标签归档:JS技术

JS获取URL参数方法

  1. //js get url param
  2.         var getParam = function(name){
  3.                 var search = document.location.search;
  4.                 var pattern = new RegExp(“[?&]”+name+”\=([^&]+)”, “g”);
  5.                 var matcher = pattern.exec(search);
  6.                 var items = null;
  7.                 if(null != matcher){
  8.                         try{
  9.                                 items = decodeURIComponent(decodeURIComponent(matcher[1]));
  10.                         }catch(e){
  11.                                 try{
  12.                                         items = decodeURIComponent(matcher[1]);
  13.                                 }catch(e){
  14.                                         items = matcher[1];
  15.                                 }
  16.                         }
  17.                 }
  18.                 return items;
  19.         };
  20. getParam(‘PId’); //获取URL参数名为PId的值