JS获取URL参数值

<script type="text/javascript"> 
<!-- 
String.prototype.GetValue
= function(para) {  
  
var reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");  
  
var r = this.substr(this.indexOf("\?")+1).match(reg);  
  
if (r!=nullreturn unescape(r[2]); return null;  
}  
var str = "www.sina.com/defalut.aspx?ID=123456";
//如果获取本页地址用var str = location.href;  

alert(str.GetValue(
"ID"));//ID就是参数  
//
--> 
</script> 
留个记号

原文地址:https://www.cnblogs.com/ret00100/p/1605357.html