比如链接 https://www.jianshu.com/writer#/notebooks/21621288/notes/29391753
我想获取29391753这个值
如下现写一个正则表达式:
String.prototype.getQuery = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = this.substr(this.indexOf("\?") + 1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
然后获取值:
var strHref = this.location.href;
var ProjectCD = strHref.getQuery("ProjectCD");
现在ProjectCD 就等于29391753