PHP成都培训中心官方网站
返回首页
当前位置: 主页 > 在线教学 >

复杂参数传递列表实现,仿360buy。

时间:2010-05-30 22:22来源:未知 作者:罗维 点击:
图片1 现在各大商城最流行的分类查询方式就如上图所示了。其实现的方法代码如下: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns
  

图片1
现在各大商城最流行的分类查询方式就如上图所示了。其实现的方法代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
本程序演示多个条件查询或是分页时,对状态的保存。@auther www.phpchengdu.com <br />
商品分类:&nbsp;
<a href="##" id="type-1" onclick="toURL(this)">全部</a>&nbsp;
<a href="##" id="type-2" onclick="toURL(this)">电视</a>&nbsp;
<a href="##" id="type-3" onclick="toURL(this)">计算机</a>&nbsp;
<a href="##" id="type-4" onclick="toURL(this)">洗衣机</a>&nbsp;
<br />
品牌:&nbsp;
<a href="##" id="brand-1" onclick="toURL(this)">全部</a>&nbsp;
<a href="##" id="brand-2" onclick="toURL(this)">索尼</a>&nbsp;
<a href="##" id="brand-3" onclick="toURL(this)">创维</a>&nbsp;
<a href="##" id="brand-4" onclick="toURL(this)">长虹</a>&nbsp;
<br />
尺寸:&nbsp;
<a href="##" id="size-1" onclick="toURL(this)">全部</a>&nbsp;
<a href="##" id="size-2" onclick="toURL(this)">32</a>&nbsp;
<a href="##" id="size-3" onclick="toURL(this)">37</a>&nbsp;
<a href="##" id="size-4" onclick="toURL(this)">42</a>&nbsp;
<br />
价格范围:&nbsp;
<a href="##" id="price-1" onclick="toURL(this)">全部</a>&nbsp;
<a href="##" id="price-2" onclick="toURL(this)">0~499</a>&nbsp;
<a href="##" id="price-3" onclick="toURL(this)">500~2000</a>&nbsp;
<a href="##" id="price-4" onclick="toURL(this)">2000以上</a>&nbsp;
<br />
按尺寸排序:&nbsp;
<a href="##" id="order-size-asc" onclick="toURL(this)">升序</a>&nbsp;
<a href="##" id="order-size-desc" onclick="toURL(this)">降序</a>&nbsp;
<br />
<input type="hidden" name="parameter" id="parameter" value="type-3,brand-3,size-4,price-3,order-size-asc" />
 where  type='3' and brand='3' and size='4' and price='3' and <br />where  type='3' and brand='3' and size='4' and price='3'<br />对应的sql语句为:select * from goods where  type='3' and brand='3' and size='4' and price='3'  order by size asc<script type="text/javascript">
function toURL(obj){
 //alert(obj.id);
 var currentParameterString=obj.id;
 var oldParameterString=document.getElementById('parameter').value;
 if(oldParameterString==''){
  oldParameterArray=new Array();
  //alert('null');
 }else{
  //oldParameterString="type-1,sise-37"
  //oldParameterArray=Array("type-1","size-37")
  var oldParameterArray=oldParameterString.split(',');//= php  explod()
 }
 var inParameter=false;
 for(var i=0;i<oldParameterArray.length;i++){
  //判断大类是否存在
  //size-3  Array('size','42');
  var currentParameterArray=currentParameterString.split('-');
  //oldParameterArray=Array("type-1","size-37")
  //"type-1"
  //tempArray=Array('type','1')
  //tempArray=Array('size','37')
  var tempArray=oldParameterArray[i].split('-');
  if(currentParameterArray[0]==tempArray[0]){
   //如果已有此类的过滤项存在,则用本次选中的过滤项替换旧的过滤项
   // oldParameterArray[1]="size-42"
   // oldParameterArray[1]="size-37"
   oldParameterArray[i]=currentParameterString;
   inParameter=true;
   break;
  }
 }
 //如果没有本类的过滤项存在,则插入新的过滤项
 if(!inParameter){
  oldParameterArray[i]=currentParameterString;
 }
 var newParameterString=oldParameterArray.join(',');
 //alert(oldParameterArray.length);
 alert(newParameterString);
 document.location='list_filter.php?parameter='+newParameterString;
}
}
}
</script>
</body>
</html>
顶一下
(9)
100%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
发布者资料
罗老师 查看详细资料 发送留言 加为好友 用户等级:高级会员 注册时间:2006-09-21 00:09 最后登录:2011-11-19 21:11
推荐内容