欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php结合js实现多条件组合查询

程序员文章站 2023-12-17 22:56:34
 本文实例为大家分享了php结合js实现多条件组合查询的具体代码,供大家参考,具体内容如下 一、效果图 二、前端代码

一、效果图

php结合js实现多条件组合查询

二、前端代码

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jquery分类</title> 
<script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
<style type="text/css"> 
 .templinkactive { 
 padding:5px; 
 text-decoration:none; 
 color:red; 
 } 
 .templink { 
 cursor:pointer; 
 padding:5px; 
 text-decoration:none; 
 } 
 table{border:1px solid #ccc;}
 table tr{ height:35px;} 
</style>
<script type="text/javascript"> 
 $(function () { 
 //品牌 
 var alink01 = $("#linktype01").find("span"); 
 alink01.click(function () { 
 alink01.each(function () { 
 $(this).removeclass("templinkactive").addclass("templink"); 
 }); 
 $(this).removeclass("templink").addclass("templinkactive"); 
 $("#brand").val($(this).attr("tag"));
 setpara();
 });

 //价格 
 var alink02 = $("#linktype02").find("span"); 
 alink02.click(function () { 
 alink02.each(function () { 
 $(this).removeclass("templinkactive").addclass("templink"); 
 }); 
 $(this).removeclass("templink").addclass("templinkactive"); 
 $("#price").val($(this).attr("tag"));
 setpara();
 }) 

 //尺寸 
 var alink03 = $("#linktype03").find("span"); 
 alink03.click(function () { 
 alink03.each(function () { 
 $(this).removeclass("templinkactive").addclass("templink"); 
 }); 
 $(this).removeclass("templink").addclass("templinkactive"); 
 $("#size").val($(this).attr("tag")); 
 setpara(); 
 }); 
 }); 

 function setpara() { 
 var brand = $("#brand").val(); 
 var price = $("#price").val(); 
 var size = $("#size").val(); 
 alert("1.php?brand=" + brand + "&price=" + price + "&size=" + size); 
 // var keywords = $("#search").val();
  // var skip_url = "http://" + window.location.hostname + window.location.pathname;
  // var url = skip_url + "?s=/admin/goods/goods_list/brand/"+brand+"/price/"+price+"/size/"+size;
  // window.location.href = url;
  // alert(url); 
 }; 
</script>
<script type="text/javascript">
 /*//tp框架-start
 $(function(){
  var brand = $("#brand").val();
  var price = $("#price").val();
  var size = $("#size").val();
  // alert(tag);
  if(brand != ''){
   $("#linktype01").find("span").removeclass("templinkactive").addclass("templink")
   $('span[tag="'+brand+'"]').css('color','red');
  }
  if(price != ''){
   $("#linktype02").find("span").removeclass("templinkactive").addclass("templink")
   $('span[tag="'+price+'"]').css('color','red');
  }
  if(size != ''){
   $("#linktype03").find("span").removeclass("templinkactive").addclass("templink")
   $('span[tag="'+size+'"]').css('color','red');
  }
 });
 //tp框架-end*/
</script>
</head> 
<body> 
 <form id="form1" runat="server"> 
 <div> 
 <table> 
 <tr id="linktype01"> 
  <td style="width:100px"> 
  <b>笔记本品牌</b> 
  </td> 
  <td> 
  <span class='templinkactive' tag="0">不限</span> 
  </td> 
  <td> 
  <span class='templink' tag="100101">联想(lenovo)</span> 
  </td> 
  <td> 
  <span class='templink' tag="100102">宏碁(acer)</span> 
  </td> 
  <td> 
  <span class='templink' tag="100103">华硕(asus)</span> 
  </td> 
  <td> 
  <span class='templink' tag="100104">戴尔(dell)</span> 
  </td> 
  <td> 
  <span class='templink' tag="100105">苹果(apple)</span> 
  </td> 
  <td> 
  <span class='templink' tag="100106">三星 (samsung)</span> 
  </td> 
 </tr> 
 <tr id="linktype02"> 
  <td style="width:100px"> 
  <b>价格范围</b> 
  </td> 
  <td> 
  <span class='templinkactive' tag="0">不限</span> 
  </td> 
  <td> 
  <span class='templink' tag="100201">1000-2999</span> 
  </td> 
  <td> 
  <span class='templink' tag="100202">3000-3499</span> 
  </td> 
  <td> 
  <span class='templink' tag="100203">4000-4499</span> 
  </td> 
  <td>
  <span class='templink' tag="100204">5000-5999</span>
  </td>
  <td>
  <span class='templink' tag="100205">6000-6999</span>
  </td>
  <td>
  <span class='templink' tag="100206">7000及以上</span>
  </td>
 </tr>
 <tr id="linktype03">
  <td style="width:100px">
  <b>尺寸范围</b>
  </td>
  <td>
  <span class='templinkactive' tag="0" >不限</span>
  </td>
  <td>
  <span class='templink' tag="100301">8.9英寸及以下</span>
  </td>
  <td>
  <span class='templink' tag="100302">11英寸</span>
  </td>
  <td>
  <span class='templink' tag="100303">12英寸</span>
  </td>
  <td>
  <span class='templink' tag="100304">13英寸</span>
  </td>
  <td>
  <span class='templink' tag="100305">14英寸</span>
  </td>
  <td>
  <span class='templink' tag="100306">15英寸及以上</span>
  <input type="hidden" id="brand" value="" />
  <input type="hidden" id="price" value="" />
  <input type="hidden" id="size" value="" />
  </td> 
 </tr> 
 </table> 
 </div> 
 </form> 
</body> 
</html>

三、服务端代码

goodscontroller.class.php

<?php
public function goods_list(){
 $brand= i('brand');
 $price= i('price');
 $size= i('size');
 $this->assign('brand',$brand);
 $this->assign('price',$price);
 $this->assign('size',$size);
 $this->display();
}
?>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: