我有以下代码:
<label class='checkbox'><input type='checkbox' class='custom_filter' name='kleuren' value='Blauw' data-taxonomy='kleuren' data-category='Blauw'> Blauw (4) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='kleuren' value='Rood' data-taxonomy='kleuren' data-category='Rood'> Rood (2) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='kleuren' value='Wit' data-taxonomy='kleuren' data-category='Wit'> Wit (2) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='kleuren' value='Zwart' data-taxonomy='kleuren' data-category='Zwart'> Zwart (1) </label>
<label>provincies</label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Drenthe' data-taxonomy='provincies' data-category='Drenthe'> Drenthe (6) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Flevoland' data-taxonomy='provincies' data-category='Flevoland'> Flevoland (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Friesland' data-taxonomy='provincies' data-category='Friesland'> Friesland (6) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Groningen' data-taxonomy='provincies' data-category='Groningen'> Groningen (5) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Limburg' data-taxonomy='provincies' data-category='Limburg'> Limburg (2) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Noord-Brabant' data-taxonomy='provincies' data-category='Noord-Brabant'> Noord-Brabant (2) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Noord-Holland' data-taxonomy='provincies' data-category='Noord-Holland'> Noord-Holland (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Overijssel' data-taxonomy='provincies' data-category='Overijssel'> Overijssel (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Utrecht' data-taxonomy='provincies' data-category='Utrecht'> Utrecht (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Zeeland' data-taxonomy='provincies' data-category='Zeeland'> Zeeland (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='provincies' value='Zuid-Holland' data-taxonomy='provincies' data-category='Zuid-Holland'> Zuid-Holland (0) </label>
<label>stijlen</label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Amerikaans' data-taxonomy='stijlen' data-category='Amerikaans'> Amerikaans (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Cabriolet' data-taxonomy='stijlen' data-category='Cabriolet'> Cabriolet (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Duits' data-taxonomy='stijlen' data-category='Duits'> Duits (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Engels' data-taxonomy='stijlen' data-category='Engels'> Engels (8) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Frans' data-taxonomy='stijlen' data-category='Frans'> Frans (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Italiaans' data-taxonomy='stijlen' data-category='Italiaans'> Italiaans (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Klassiek' data-taxonomy='stijlen' data-category='Klassiek'> Klassiek (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Luxe' data-taxonomy='stijlen' data-category='Luxe'> Luxe (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='stijlen' value='Modern' data-taxonomy='stijlen' data-category='Modern'> Modern (0) </label>
<label>merken</label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='merken' value='Austin' data-taxonomy='merken' data-category='Austin'> Austin (7) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='merken' value='Bentley' data-taxonomy='merken' data-category='Bentley'> Bentley (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='merken' value='BMW' data-taxonomy='merken' data-category='BMW'> BMW (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='merken' value='Cadillac' data-taxonomy='merken' data-category='Cadillac'> Cadillac (1) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='merken' value='Chevrolet' data-taxonomy='merken' data-category='Chevrolet'> Chevrolet (0) </label>
<label class='checkbox'><input type='checkbox' class='custom_filter' name='merken' value='Chrysler' data-taxonomy='merken' data-category='Chrysler'> Chrysler (0) </label>
这表示用于将过滤器应用于数据库查询的表单。单击每个过滤器(设置复选框)后,必须刷新 URL HASH,如下所示:
#provincies=Drehte,Noord-Brabant&kleuren=Wit,Rood
如果选中了选定的省份和颜色,这是一个示例。
我试过做
var filters = jQuery("#CUSTOM_AJAX_FILTERS").serializeArray();
其中 filters var 将从表单中获取所有数据,作为数组,但它始终返回一个空数组。我还尝试获取数据分类和数据类别(其中分类 = 类别;& 类别 = 过滤器)并使用 window.location.hash 获取 url 哈希并将所有内容拆分,附加新数据或删除等。但这不是一个好的选择。
请让我知道是否有任何其他解决方案可以使用 ajax / 使用选中的复选框轻松构建 url 哈希,而无需刷新页面。
谢谢!