我的javascript

//删除querystring指定key,__VIEWSTATEGENERATOR & __VIEWSTATE
function removeQueryStringKey(query, key) {
    var p = "&" + key + "=[^&]{0,}";
    p += "|" + key + "=[^&]{0,}&";
    var reg = new RegExp(p);
    return query.replace(reg, "");
}

//获取querystring指定key的value
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}


    //添加querystring到cookie
    function addCookieQuery(query) {
        var vars = query.split('&');
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split('=');
            var key = decodeURIComponent(pair[0]);
            var value = decodeURIComponent(pair[1]);
            $.cookie(key, value);
        }
    }
    原文作者:Chobits
    原文地址: https://segmentfault.com/a/1190000000728655
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞