js获取url参数值
request()函数获取url参数值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<script type="text/javascript" src="jquery-1.8.3.js"></script> <script type="text/javascript"> function request(paras){ var url = location.href; var paraString = url.substring(url.indexOf("?")+1,url.length).split("&"); var paraObj = {} for (i=0; j=paraString[i]; i++){ paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length); } var returnValue = paraObj[paras.toLowerCase()]; if(typeof(returnValue)=="undefined"){ return ""; }else{ return returnValue; } } $(function(){ var fid = request("fid") if(fid != ''){ var url = $("a").attr('href'); $("a").attr('href',url+'?from='+fid); } }) </script> <a href="http://www.baidu.com" target="_blank">百度</a> |
Read more