熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JS 修改URL參數

2022-06-13   來源: JSP教程 
本篇文章是對JS修改URL參數的實現代碼進行了詳細的分析介紹需要的朋友參考下   復制代碼 代碼如下:

  
function changeURLPar(url ref value) {
    var str = "";
    if (urlindexOf(?) != )
        str = urlsubstr(urlindexOf(?) + );
    else
        return url + "?" + ref + "=" + value;
    var returnurl = "";
    var setparam = "";
    var arr;
    var modify = "";
    if (strindexOf(&) != ) {
        arr = strsplit(&);
        for (i in arr) {
            if (arr[i]split(=)[] == ref) {
                setparam = value;
                modify = "";
            }
            else {
                setparam = arr[i]split(=)[];
            }
            returnurl = returnurl + arr[i]split(=)[] + "=" + setparam + "&";
        }
        returnurl = returnurlsubstr( returnurllength );
        if (modify == "")
            if (returnurl == str)
                returnurl = returnurl + "&" + ref + "=" + value;
    }
    else {
        if (strindexOf(=) != ) {
            arr = strsplit(=);
            if (arr[] == ref) {
                setparam = value;
                modify = "";
            }
            else {
                setparam = arr[];
            }
            returnurl = arr[] + "=" + setparam;
            if (modify == "")
                if (returnurl == str)
                    returnurl = returnurl + "&" + ref + "=" + value;
        }
        else
            returnurl = ref + "=" + value;
    }
    return urlsubstr( urlindexOf(?)) + "?" + returnurl;
}


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20032.html
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.