JS添加修改URL参数

View Code
    function ChangeParam(name, value) {
        var url = window.location.href;
        var newUrl = "";
        var reg = new RegExp("(^|)" + name + "=([^&]*)(|$)");
        var tmp = name + "=" + value;
        if (url.match(reg) != null) {
            newUrl = url.replace(eval(reg), tmp);
        }
        else {
            if (url.match("[\?]")) {
                newUrl = url + "&" + tmp;
            }
            else {
                newUrl = url + "?" + tmp;
            }
        }
        location.href = newUrl;
    }

 

posted @ 2013-05-06 14:48  坐在地狱,仰望天堂  阅读(534)  评论(0编辑  收藏  举报