Jquery添加 或者修改url中參數的值


        // 添加 或者 修改 url中參數的值
        function UpdateUrlParam(name, val) {
            var thisURL = document.location.href;

            // 如果 url中包含這個參數 則修改
            if (thisURL.indexOf(name+'=') > 0) {
                var v = getUrlParam(name);
                if (v != null) {
                    // 是否包含參數
                    thisURL = thisURL.replace(name + '=' + v, name + '=' + val);

                }
                else {
                    thisURL = thisURL.replace(name + '=', name + '=' + val);
                }
                
            } // 不包含這個參數 則添加
            else {
                if (thisURL.indexOf("?") > 0) {
                    thisURL = thisURL + "&" + name + "=" + val;
                }
                else {
                    thisURL = thisURL + "?" + name + "=" + val;
                }
            }
            location.href = thisURL;

        };

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM