1. 程式人生 > >獲取url的引數:getUrlParam

獲取url的引數:getUrlParam

declare function unescape(string: string): string; // 引用
// 使用
getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //構造一個含有目標引數的正則表示式物件
    // console.log(reg);
    var r = decodeURI(window.location.search).substr(1).match(reg);  //匹配目標引數
    // console.log(window.location.search.substr(1).match(reg));
if (r != null) return unescape(r[2]); return null; //返回引數值 }