回答編集履歴
1
コメントを受けて追記
answer
CHANGED
@@ -73,4 +73,58 @@
|
|
73
73
|
$(`.list`).not(categorySelector).hide();
|
74
74
|
}
|
75
75
|
|
76
|
+
```
|
77
|
+
|
78
|
+
##### コメントを受けて追記
|
79
|
+
|
80
|
+
```js
|
81
|
+
$(function() {
|
82
|
+
$('input[name="catItems[]"]').on('change', function() {
|
83
|
+
var catItems = [];
|
84
|
+
$('input[name="catItems[]"]:checked').each(function() {
|
85
|
+
catItems.push('<li class="tag-item">' + $(this).val() + '<span class="close"></span></li>');
|
86
|
+
});
|
87
|
+
|
88
|
+
$('ul.tag-list').html(catItems);
|
89
|
+
|
90
|
+
$('.tag-item').on('click', function(){
|
91
|
+
$(this).remove();
|
92
|
+
|
93
|
+
var text = $(this).text();
|
94
|
+
$('.list-options input[value=' + text + ']').prop( 'checked', false );
|
95
|
+
|
96
|
+
});
|
97
|
+
|
98
|
+
});
|
99
|
+
|
100
|
+
$('#clear').on('click', function(e) {
|
101
|
+
if($("input:checkbox[name='catItems[]']").prop( 'checked', false )){
|
102
|
+
|
103
|
+
$("input:checkbox[name='catItems[]']").prop( 'checked', false );
|
104
|
+
$('ul.tag-list').html('');
|
105
|
+
|
106
|
+
}
|
107
|
+
|
108
|
+
return false;
|
109
|
+
|
110
|
+
});
|
111
|
+
|
112
|
+
$('form').on('submit', function(e){
|
113
|
+
e.preventDefault();
|
114
|
+
|
115
|
+
$('.list').show();
|
116
|
+
for ( let category of ['sex', 'tanmatsu', 'location'] ){ //カテゴリごとに
|
117
|
+
// チェックされている条件を配列化
|
118
|
+
const categoryItems = Array.from( $(`input[data-category~="${category}"]:checked`), e => e.value );
|
119
|
+
// 何もチェックされていなければスキップ
|
120
|
+
if ( categoryItems.length == 0 ) continue;
|
121
|
+
// チェックされている条件のリストを抜き出すセレクタ
|
122
|
+
const categorySelector = categoryItems.map( item => `div[data-${category}~="${item}"]`).join();
|
123
|
+
// 条件を反転して隠す
|
124
|
+
$(`.list`).not(categorySelector).hide();
|
125
|
+
}
|
126
|
+
|
127
|
+
});
|
128
|
+
|
129
|
+
});
|
76
130
|
```
|