为了账号安全,请及时绑定邮箱和手机立即绑定

有个js不会写大牛么教教我

有个js不会写大牛么教教我

欧罗巴皇 2016-12-10 16:38:04
 $.getQueryString = function (name) {        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");        var r = window.location.search.substr(1).match(reg);        if (r != null) return unescape(r[2]); return null;    }这样只有地址栏是这样www.imooc.com?id=3&pd=10  才能获取值 但是结构是这样就不行了 www.imooc.com?#3id=3&pd=10 或者这样的www.imooc.com?id=3&pd=10#3怎么样让location.hash和进去
查看完整描述

1 回答

?
Ewall_

TA贡献27条经验 获得超9个赞

        function getQueryStringArgs(){
		var qs=(location.search.length>0 ? location.search.substring(1) : ""),
			args={},
			items=qs.length ? qs.split("&") : [],
			item=null,
			name=null,
			value=null,
			i=0,
			len=items.length;
		for(i=0;i<len;i++){
			item=items[i].split("=");	
			name=decodeURIComponent(item[0]);
			value=decodeURIComponent(item[1]);
			if(name.length){
				args[name]=value;
			}
		}
		return args;
	}


查看完整回答
反对 回复 2017-02-11
  • 1 回答
  • 0 关注
  • 1410 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信