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

https://www.jb51.net/article/162069.htm

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

一、效果图

二、前端代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Jquery分类</title>
<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="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="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="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

1
2
3
4
5
6
7
8
9
10
11
<?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();
}
?>

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

                        <div class="art_xg">
                            <b>您可能感兴趣的文章:</b><ul><li><a href="/article/126527.htm" title="thinkPHP5实现的查询数据库并返回json数据实例" target="_blank">thinkPHP5实现的查询数据库并返回json数据实例</a></li><li><a href="/article/64221.htm" title="php简单实现查询数据库返回json数据" target="_blank">php简单实现查询数据库返回json数据</a></li><li><a href="/article/63756.htm" title="PHP中把数据库查询结果输出为json格式简单实例" target="_blank">PHP中把数据库查询结果输出为json格式简单实例</a></li></ul>
                        </div>

                    </div>
原文地址:https://www.cnblogs.com/sunny3158/p/15105174.html