适用场景:多条件查询情况,如下图所示:
通过设置URL参数,再结合数据源控件设置的RUL参数,就能进行简单的多条件查询了。
javascript函数:
<mce:script type="text/javascript"><!-- //设置URL参数的方法 function setParmsValue(parms, parmsValue) { var urlstrings = document.URL; var args = GetUrlParms(); var values = args[parms]; //如果参数不存在,则添加参数 if (values == undefined) { var query = location.search.substring(1); //获取查询串 //如果Url中已经有参数,则附加参数 if (query) { urlstrings += ("&" + parms + "=" + parmsValue); } else { urlstrings += ("?" + parms + "=" + parmsValue); //向Url中添加第一个参数 } window.location = urlstrings; } else { window.location = updateParms(parms, parmsValue); //修改参数 } } //修改URL参数,parms:参数名,parmsValue:参数值,return:修改后的URL function updateParms(parms, parmsValue) { var newUrlParms = ""; var newUrlBase = location.href.substring(0, location.href.indexOf("?") + 1); //截取查询字符串前面的url var query = location.search.substring(1); //获取查询串 var pairs = query.split("&"); //在逗号处断开 for (var i = 0; i < pairs.length; i++) { var pos = pairs[i].indexOf('='); //查找name=value if (pos == -1) continue; //如果没有找到就跳过 var argname = pairs[i].substring(0, pos); //提取name var value = pairs[i].substring(pos + 1); //提取value //如果找到了要修改的参数 if (findText(argname, parms)) { newUrlParms = newUrlParms + (argname + "=" + parmsValue + "&"); } else { newUrlParms += (argname + "=" + value + "&"); } } return newUrlBase + newUrlParms.substring(0, newUrlParms.length - 1); } //辅助方法 function findText(urlString, keyWord) { return urlString.toLowerCase().indexOf(keyWord.toLowerCase()) != -1 ? true : false; } //得到查询字符串参数集合 function GetUrlParms() { var args = new Object(); var query = location.search.substring(1); //获取查询串 var pairs = query.split("&"); //在逗号处断开 for (var i = 0; i < pairs.length; i++) { var pos = pairs[i].indexOf('='); //查找name=value if (pos == -1) continue; //如果没有找到就跳过 var argname = pairs[i].substring(0, pos); //提取name var value = pairs[i].substring(pos + 1); //提取value args[argname] = unescape(value); //存为属性 } return args; } // --></mce:script>
测试代码:
<body> <input type="button" id="Button1" οnclick="setParmsValue('Test1','AAA')" value="设置URL参数[Test1=AAA]" /> <input type="button" id="Button2" οnclick="setParmsValue('Test1','BBB')" value="设置URL参数[Test1=BBB]" /> <input type="button" id="Button3" οnclick="setParmsValue('Test2','AAA')" value="设置URL参数[Test2=AAA]" /> <input type="button" id="Button4" οnclick="setParmsValue('Test2','BBB')" value="设置URL参数[Test2=BBB]" /> </body>