动态构造地址栏参数
大半天的时间 做个 动态构造 地址栏参数 的小功能。。浪费时间。。没弄出来。今天一大早来公司就开始在 csdn找资料。后来看到别人写的一段JS代码。。。没错。是我要的。。。赶紧收藏一下!!
<script type='text/javascript'>
RegExp.escape = function(str) {
return (str||'').replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
};
function changeParam(name, value) {
name = encodeURIComponent(name);
var p = name + "=" + encodeURIComponent(value);
var href = location.href;
if (!/\?/.test(href))
return location.href = href.replace(/[^?&=#]+/, '$&?' + p);
if (new RegExp("\\b" + RegExp.escape(name) + "=", "ig").test(href.split("?")[1]))
return location.href = href.replace(new RegExp("\\b" + RegExp.escape(name) + "\\=[^&#]*", "ig"), p);
return location.href = href.replace(/[^?&=#]+\?/, '$&' + p + "&");
}
</script>
<select name="select1" onchange="changeParam('n', this.value)">
<option selected>请选择</option>
<option value="1">第一项</option>
<option value="2">第二项</option>
</select>
原帖地址:http://topic.csdn.net/u/20100320/16/6A914B5A-8B94-4741-9C2D-149CE31DAD5F.html
浙公网安备 33010602011771号