回答編集履歴
1
コメントを受けて追記
test
CHANGED
@@ -149,3 +149,111 @@
|
|
149
149
|
|
150
150
|
|
151
151
|
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
##### コメントを受けて追記
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```js
|
160
|
+
|
161
|
+
$(function() {
|
162
|
+
|
163
|
+
$('input[name="catItems[]"]').on('change', function() {
|
164
|
+
|
165
|
+
var catItems = [];
|
166
|
+
|
167
|
+
$('input[name="catItems[]"]:checked').each(function() {
|
168
|
+
|
169
|
+
catItems.push('<li class="tag-item">' + $(this).val() + '<span class="close"></span></li>');
|
170
|
+
|
171
|
+
});
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
$('ul.tag-list').html(catItems);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
$('.tag-item').on('click', function(){
|
180
|
+
|
181
|
+
$(this).remove();
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
var text = $(this).text();
|
186
|
+
|
187
|
+
$('.list-options input[value=' + text + ']').prop( 'checked', false );
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
});
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
});
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
$('#clear').on('click', function(e) {
|
200
|
+
|
201
|
+
if($("input:checkbox[name='catItems[]']").prop( 'checked', false )){
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
$("input:checkbox[name='catItems[]']").prop( 'checked', false );
|
206
|
+
|
207
|
+
$('ul.tag-list').html('');
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
return false;
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
});
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
$('form').on('submit', function(e){
|
224
|
+
|
225
|
+
e.preventDefault();
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
$('.list').show();
|
230
|
+
|
231
|
+
for ( let category of ['sex', 'tanmatsu', 'location'] ){ //カテゴリごとに
|
232
|
+
|
233
|
+
// チェックされている条件を配列化
|
234
|
+
|
235
|
+
const categoryItems = Array.from( $(`input[data-category~="${category}"]:checked`), e => e.value );
|
236
|
+
|
237
|
+
// 何もチェックされていなければスキップ
|
238
|
+
|
239
|
+
if ( categoryItems.length == 0 ) continue;
|
240
|
+
|
241
|
+
// チェックされている条件のリストを抜き出すセレクタ
|
242
|
+
|
243
|
+
const categorySelector = categoryItems.map( item => `div[data-${category}~="${item}"]`).join();
|
244
|
+
|
245
|
+
// 条件を反転して隠す
|
246
|
+
|
247
|
+
$(`.list`).not(categorySelector).hide();
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
});
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
});
|
258
|
+
|
259
|
+
```
|