var aa = '?name=hss&age=13';
        function strToObj(str){
            if(typeof str === 'undefined'){
                str = location.search;
            }
            var reg = /[?|&]+(w+)=(w*)/g;
            var param = {};
            do{
                var item = reg.exec(str);
                if(item !== null){
                    param[item[1]] = item[2]
                }
            }while(reg.lastIndex > 0)
            return param;
        }
        console.time()
        console.log(strToObj());
        console.timeEnd()


执行效率还是蛮高的大概在一毫秒吧

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!