回答編集履歴

3

追記

2018/03/26 08:46

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -119,3 +119,121 @@
119
119
  </div>
120
120
 
121
121
  ```
122
+
123
+
124
+
125
+
126
+
127
+ # カテゴリごとにand検索、ただしカテゴリ内はor検索
128
+
129
+ ```javascript
130
+
131
+ $(function(){
132
+
133
+ $('[type=checkbox]').on('change',function(){
134
+
135
+ if($('#style,#color,#size').find('[type=checkbox]:checked').length==0){
136
+
137
+ $('.result section').show();
138
+
139
+ }else{
140
+
141
+ var myList=[];
142
+
143
+ ["style","color","size"].forEach(function(x){
144
+
145
+ if($('#'+x+' [type=checkbox]:checked').length>0){
146
+
147
+ myList.push($('#'+x+' [type=checkbox]:checked').map(function(){return '.'+$(this).attr('id');}).get());
148
+
149
+ }
150
+
151
+ });
152
+
153
+ var classList=[];
154
+
155
+ for(var i=0;i<myList.length;i++){
156
+
157
+ if(classList.length==0) classList=myList[i];
158
+
159
+ if(i>=myList.length-1) break;
160
+
161
+ var tmp=[];
162
+
163
+ for(var j=0;j<classList.length;j++){
164
+
165
+ for(var k=0;k<myList[i+1].length;k++){
166
+
167
+ tmp.push(classList[j]+myList[i+1][k]);
168
+
169
+ }
170
+
171
+ }
172
+
173
+ classList=tmp;
174
+
175
+ }
176
+
177
+ $('.result section').hide().filter(classList.join(",")).show();
178
+
179
+ }
180
+
181
+ }).eq(0).trigger('change');
182
+
183
+ });
184
+
185
+ ```
186
+
187
+ ```HTML
188
+
189
+ <form>
190
+
191
+ <div id="select" >
192
+
193
+ <input type="button" value="ALL" onclick="allselect()">
194
+
195
+ <div id="style"><!--「style」と「color」と「size」はor検索-->
196
+
197
+ <label for="shirt"><input type="checkbox" id="shirt">シャツ</label>
198
+
199
+ <label for="skirt"><input type="checkbox" id="skirt">スカート</label>
200
+
201
+ <label for="another"><input type="checkbox" id="another">その他</label>
202
+
203
+ </div>
204
+
205
+ <div id="color">
206
+
207
+ <label for="white"><input type="checkbox" id="white">ホワイト</label>
208
+
209
+ <label for="pink"><input type="checkbox" id="pink">ピンク</label>
210
+
211
+ <label for="yellow"><input type="checkbox" id="yellow">イエロー</label>
212
+
213
+ </div>
214
+
215
+ <div id="size">
216
+
217
+ <label for="l"><input type="checkbox" id="l">Lサイズ</label>
218
+
219
+ <label for="m"><input type="checkbox" id="m">Mサイズ</label>
220
+
221
+ </div>
222
+
223
+ </div>
224
+
225
+ </form>
226
+
227
+
228
+
229
+ <div class="result">
230
+
231
+ <section class="shirt white l">シャツ 白 L</section>
232
+
233
+ <section class="skirt white m">スカート 白 M</section>
234
+
235
+ <section class="skirt pink l">スカート ピンク L</section>
236
+
237
+ </div>
238
+
239
+ ```

2

追記

2018/03/26 08:46

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -29,3 +29,93 @@
29
29
 
30
30
 
31
31
  よくよく仕様を検討しなおしてみてください
32
+
33
+
34
+
35
+ # sample
36
+
37
+ すべてor検索
38
+
39
+ ```javascript
40
+
41
+ $(function(){
42
+
43
+ $('[type=checkbox]').on('change',function(){
44
+
45
+ var classList=[];
46
+
47
+ if($('#style,#color,#size').find('[type=checkbox]:checked').length==0){
48
+
49
+ $('.result section').show();
50
+
51
+ }else{
52
+
53
+ $('#style,#color,#size').find('[type=checkbox]:checked').each(function(){
54
+
55
+ classList.push("."+$(this).attr('id'));
56
+
57
+ });
58
+
59
+ $('.result').find('section').hide().end().find(classList.join(',')).show();
60
+
61
+ }
62
+
63
+ }).eq(0).trigger('change');
64
+
65
+ });
66
+
67
+ ```
68
+
69
+ ```HTML
70
+
71
+ <form>
72
+
73
+ <div id="select" >
74
+
75
+ <input type="button" value="ALL" onclick="allselect()">
76
+
77
+ <div id="style"><!--「style」と「color」と「size」はor検索-->
78
+
79
+ <label for="shirt"><input type="checkbox" id="shirt">シャツ</label>
80
+
81
+ <label for="skirt"><input type="checkbox" id="skirt">スカート</label>
82
+
83
+ <label for="another"><input type="checkbox" id="another">その他</label>
84
+
85
+ </div>
86
+
87
+ <div id="color">
88
+
89
+ <label for="white"><input type="checkbox" id="white">ホワイト</label>
90
+
91
+ <label for="pink"><input type="checkbox" id="pink">ピンク</label>
92
+
93
+ <label for="yellow"><input type="checkbox" id="yellow">イエロー</label>
94
+
95
+ </div>
96
+
97
+ <div id="size">
98
+
99
+ <label for="l"><input type="checkbox" id="l">Lサイズ</label>
100
+
101
+ <label for="m"><input type="checkbox" id="m">Mサイズ</label>
102
+
103
+ </div>
104
+
105
+ </div>
106
+
107
+ </form>
108
+
109
+
110
+
111
+ <div class="result">
112
+
113
+ <section class="shirt white l">シャツ 白 L</section>
114
+
115
+ <section class="skirt white m">スカート 白 M</section>
116
+
117
+ <section class="skirt pink l">スカート ピンク L</section>
118
+
119
+ </div>
120
+
121
+ ```

1

追記

2018/03/26 05:55

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  - skirtかつwhiteかつmのand検索なのか
8
8
 
9
- - skirtwhitemのor検索なのか
9
+ - skirtまたはwhiteまたはmのor検索なのか
10
10
 
11
11
 
12
12
 
@@ -22,4 +22,10 @@
22
22
 
23
23
  and検索をする(選ばれていない項目は全部がヒット)ということでしょうか?
24
24
 
25
+ またand検索の場合仮にcolorがwhiteとpinkの両方を選ぶと、whiteかつpinkは有りえないので
26
+
27
+ ヒットがなくなると思います。
28
+
29
+
30
+
25
31
  よくよく仕様を検討しなおしてみてください