缘起:【Happy   New   Year】请用函数讲话!(有免费好礼) [推荐] 
http://topic.csdn.net/u/20091229/10/9dffa813-1a6b-4583-bc72-120364cf509c.html?52239
#3 xiaojing7 (枯井) 给俺的回帖!首先感谢 xiaojing7 的大力支持!另,300 分贴暂不结贴,用于收集代码,对于有效回复,俺会认真分析整理后将结果公布。俺对 getQueryStringRegExp 进行了修正、扩展,以下是扩展及测试代码,望与大家分享!L@_@K
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Happy New Year 2010</title>
</head>
<body>
    <h2>
        Happy New Year 2010
    </h2>    <script type="text/javascript">
        // 检测器。
        var Tester = {
            // 检测器是否已初始化。
            IsInitialized: false,
            // 检测器输出窗口。
            OutputWindow: null
        };
        Tester.PrepareOutputWindow = function() {
            /// <summary>
            /// 准备 检测器输出窗口。
            /// </summary>            if (!this.IsInitialized) {
                this.OutputWindow = document.body.appendChild(document.createElement("div"));                this.OutputWindow.style.backgroundColor = "black";
                this.OutputWindow.style.color = "#c0c0c0";
                this.OutputWindow.style.border = "1px dotted blue";
                this.OutputWindow.style.fontFamily = "Verdana";
                this.OutputWindow.style.fontSize = "16px";
                this.OutputWindow.style.padding = "5px 5px 5px 5px";                this.IsInitialized = true;
            }
        };
        Tester.Highlight = function(sText) {
            /// <summary>
            /// 高亮给定文本。
            /// </summary>
            /// <param name="sText">String,必选项,给定文本。</param>            if (sText != "")
                return "<b style='color: yellow'>" + sText + "</b>";
            else
                return sText;
        };
        Tester.Assert = function(sTestName, bCondition, sMessage) {
            /// <summary>
            /// 检查条件,如果该条件为 false,则显示消息。
            /// </summary>
            /// <param name="sTestName">String,必选项,当前测试名称或被测试的方法名。</param>
            /// <param name="bCondition">Boolean,必选项,若要禁止显示消息,则为 true;否则为 false。</param>
            /// <param name="sMessage">String,必选项,要显示的消息。</param>            this.PrepareOutputWindow();            var BR = "<br />";
            var output = "<hr />";            output += "Output time: " + (new Date()).toLocaleString() + BR;            if (!bCondition) {
                output += this.Highlight(sTestName) + ": " + sMessage;
            }
            else {
                output += "<span style='color: #c0ffc0'>" + sTestName + ": succeed." + "</span>";
            }            this.OutputWindow.innerHTML += output;
        };
        Tester.WriteLine = function(paramsText) {
            /// <summary>
            /// 输出单行文本。
            /// </summary>
            /// <param name="sText">String,可选项,以逗号分隔的输出文本序列。</param>            this.PrepareOutputWindow();            var text = "";
            for (var i = 0, len = arguments.length; i < len; i++) {
                text += arguments[i];
            }
            this.OutputWindow.innerHTML += "<br />" + text;
        };        window.location.ResetQueryString = function() {
            /// <summary>
            /// 重置 查询字符串。
            /// </summary>            location.QueryString = {};
        };
        window.location.ParseQueryString = function(decodeFunc) {
            /// <summary>
            /// 从当前 URL 中解析 查询字符串。
            /// </summary>
            /// <param name="decodeFunc">Function,可选项,给定的查询值解码函数,缺省为 decodeURIComponent。</param>            this.ResetQueryString();            if (decodeFunc === undefined)
                decodeFunc = decodeURIComponent;            var regQueryString = /(\?|&)(\w+)=([^&]*)/g;
            var arr;
            while ((arr = regQueryString.exec(location.search)) != null) {
                location.QueryString[arr[2]] = decodeFunc(arr[3]);
            }
        };
        window.location.GetQueryValue = function(sName, decodeFunc) {
            /// <summary>
            /// 从当前 URL 的查询字符串中,根据给定的查询参数名称获取相应的查询值。
            /// 若存在查询参数名称,则返回相应的查询值,否则返回 undefined。
            /// </summary>
            /// <param name="sName">String,必选项,给定的查询参数名称。</param>
            /// <param name="decodeFunc">Function,可选项,给定的查询值解码函数,缺省为 decodeURIComponent。</param>
            /// <returns>若存在查询参数名称,则返回相应的查询值,否则返回 undefined。</returns>            if (location.search.length > 0) {
                if (location.QueryString === undefined)
                    this.ParseQueryString(decodeFunc);                return location.QueryString[sName];
            }            return undefined;
        };
        window.location.AppendQueryString = function(sName, sValue, encodeFunc) {
            /// <summary>
            /// 追加 查询字符串。
            /// </summary>
            /// <param name="sName">String,必选项,给定的查询参数名称。</param>
            /// <param name="sValue">String,必选项,给定的查询值字符串。</param>
            /// <param name="encodeFunc">Function,可选项,给定的查询值编码函数,缺省为 encodeURIComponent。</param>            if (location.QueryString === undefined)
                this.ResetQueryString();            if (encodeFunc === undefined)
                encodeFunc = encodeURIComponent;            this.QueryString[sName] = encodeFunc(sValue);
        };
        window.location.JoinQueryString = function() {
            /// <summary>
            /// 拼接 查询字符串,并返回,若不存在查询参数,则返回空字符串。
            /// </summary>
            /// <returns>查询字符串,若不存在查询参数,则返回空字符串。</returns>            var search = new Array();            for (var name in this.QueryString) {
                search.push(name + "=" + this.QueryString[name]);
            }            return search.join("&");
        };        // Test Code.
        var v1, v2, v3;
        v1 = "http://hi.csdn.net/高+老+庄   /   ";
        v2 = "2";
        v3 = "  999  ";
        if (window.location.search.length == 0) {
            window.location.AppendQueryString("href", v1);
            window.location.AppendQueryString("b", v2);
            window.location.AppendQueryString("c", v3);            location.search = location.JoinQueryString();
        }
        //*
        Tester.WriteLine(location.GetQueryValue("href"));
        Tester.WriteLine(location.GetQueryValue("b"));
        Tester.WriteLine(location.GetQueryValue("c"));
        //*/
        Tester.Assert("location.GetQueryValue", location.GetQueryValue("c") === v3, "查询参数 c 应为" + v3);
        Tester.Assert("location.GetQueryValue", location.GetQueryValue("href") === v1, "查询参数 href 的查询值有误。");
        Tester.Assert("location.GetQueryValue", location.GetQueryValue("abc") === undefined, "查询参数 abc 应为 undefined。");
    </script></body>
</html>