JavaScript封装的方法(持续更新中。。。)

  1. 从Url中获取指定的参数
//window的location对象,得到的是url中query部分,返回一个从指定位置开始的指定长度的子字符串,这里设置为1是为了把url中的?号去掉
var a = getQueryString(url.substr(1), "ctype");
//从url中获取指定的参数(url参数, 要获取的参数)
function getQueryString(a, b) {
	a = a.match(new RegExp("(^|&)" + b + "=([^&]*)(&|$)"));
	return null != a ? a[2] : ""
}
  1. 把url中的请求参数存到数组当中
function GetRequest(url) {
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substring(url.indexOf("?")+1,url.length);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

猜你喜欢

转载自blog.csdn.net/weixin_40022980/article/details/83009191
今日推荐