html中通过javaScript获取请求中传递的参数

方法一: 

function getQueryVariable(variable)
   {
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
  }

 


方法二:
  
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}

 
posted @ 2020-02-15 13:23  听~风在北边  阅读(1096)  评论(0编辑  收藏  举报