用正则获取url上的参数
例如:http://localhost:8090/pages/index.html#/pay/real?code=5&state=1234#
需获取code和state的值
var reg1 = new RegExp("(\\?|&)code([^&]*)(?=(&|$))");
var reg2 = new RegExp("(\\?|&)state([^&]*)(?=(#|&))");
this.url = window.location.toString()//获取当前url,并转成字符串
alert(this.url)
//匹配第一个正则表达式,并根据等于号分割
this.code = this.url.match(reg1)[0].split("=")[1]
//匹配第二个正则表达式,并根据等于号分割
this.state = this.url.match(reg2)[0].split("=")[1]
alert(this.code)