console.log(getQueryString("useless")); function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i"); var r = window.location.search.substr(1).match(reg); var q = window.location.pathname.substr(1).match(reg_rewrite); if(r != null){ return unescape(r[2]); }else if(q != null){ return unescape(q[2]); }else{ return null; } }
上面这种方法适用于以下两种模式,来获取url参数值:
/User/vip_card_manager/useless/219/id/18
/User/vip_card_manager?useless=219&id=18