参数格式 /book-orn?name=1
url参数解析参数:
var a = "http://127.0.0.1/test/book-orn?name=1"
var pattern = /\?.*=(\d+)?/
a.match(pattern)
["?name=1", "1"]
hash解析参数:
var a = "http://127.0.0.1/test/book-orn/#/name=1"
var pattern = /\/#\/.*=(\d+)?/
a.match(pattern)
["/#/name=1", "1"]
js可以通过以下方法获取url地址的参数:1、比如有如下url请求:
http://zhidao.baidu.com/question/586494936989579005.html?entry=business_qb&ishq=1
2、可以用一下方法获取参数:
var params = function(str) {
function urldecode(str) {
return decodeURIComponent((str+'').replace(/\+/g, '%20'))
}
function transformToAssocArray( prmstr ) {
var params = {}
var prmarr = prmstr.split("&")
for ( var i = 0i <prmarr.lengthi++) {
var tmparr = prmarr[i].split("=")
params[tmparr[0]] = urldecode(tmparr[1])
}
return params
}
var prmstr = window.location.search.substr(1)
return prmstr != null &&prmstr != "" ? transformToAssocArray(prmstr) : {}
}()