var url = window.location.href.split("?"); if(url.length>1){ var theRequest = new Object();//theRequest为i获取的参数集合 var strs = url[1].split('&'); for(var i=0;i<strs.length;i++){ theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); } if( theRequest["xxxx"]=='true'){//获取相应参数进行相关操作 $("#sidenav").attr("display","block"); $("#topnav").attr("display","block"); }else{ $("#sidenav").attr("hidden","none"); $("#topnav").attr("hidden","none"); } }
-------------------------------------
第二种写法
// 获取url 参数 window.getQueryString = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); //(r[2]); }else{ var index1 = window.location.href.indexOf('?'); if(index1>=0){ tempURL= window.location.href.substring(index1+1); r = tempURL.match(reg); if(r == null){ var index2 = tempURL.indexOf('?'); if(index2){ r = tempURL.substring(index2+1).match(reg); } } }else{ r = window.location.href.substring(0).match(reg); } if (r != null) { return unescape(r[2]); //(r[2]); } } return ''; };