js 如何实现url的动态拼接,只要是想实现多条件筛选价格:<a href="dianqi.aspx?dq=1">1000</a><a href="dianqi.aspx?dq=2">1500</a>
品牌:<a href="dianqi.aspx?pp=1">松下</a><a href="dianqi.aspx?pp=2">索尼</a>如何实现任意拼接,各位大神 帮帮忙。
品牌:<a href="dianqi.aspx?pp=1">松下</a><a href="dianqi.aspx?pp=2">索尼</a>如何实现任意拼接,各位大神 帮帮忙。
第一步,点击价格: dianqi.aspx?dq=1
第二步,点击品牌: dianqi.aspx?dq=1&pp=1如果第一步 ,点击品牌 :dianqi.aspx?pp=1
第二步,点击价格:dianqi.aspx?pp=1&dq=1
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var a="";
function test(add){
if(a.length>0){
a+="&"+add;
}else{
a+=add;
}
}
function show(){
alert(a);
//window.location.href=".....?"+a;
}
</script>
</head><body>
<a href="javascript:test('name=test')">name</a>
<a href="javascript:test('age=20')">age</a>
<a href="javascript:test('sex=1')">name</a>
<input type="button" onclick="show()" value="show">
</body>
</html>
类似于这样?子集做个重复判断
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var a="";
var context=[];
function test(key,value){
context[key]=value;
}
function show(){
a="";
for(var i in context){
if(a.length==0){
a+=i+"="+context[i];
}else{
a+="&"+i+"="+context[i];
}
}
alert(a);
}
</script>
</head><body>
<a href="javascript:test('name','test')">name</a>
<a href="javascript:test('age','20')">age</a>
<a href="javascript:test('sex','1')">sex</a>
<input type="button" onclick="show()" value="show">
</body>
</html>
大体这样试试