【发布时间】:2019-08-22 13:50:02
【问题描述】:
我正在尝试向 Wordpress 主题的“搜索过滤器部分”添加条件(这就是我使用的选择器不简单的原因)。
有一个带有选项的下拉列表(它们是分类法,在英文“types-of-seating”中称为“tipo-de-montaje”),我需要根据下拉值显示元素。
The catch seems that what I'm trying to do works once, then when another option from dropdown is selected, I would need to reload the page in order to hide the current element and show the new one.
第一个问题是我是否首先需要 AJAX?
这是我的第二次尝试:
//Get the value of the selected option (from a dropdown)
var montajeVal = $('input[name="tipos-de-montaje"]').val();
//The containers of the elements that will be shown or hidden
const escuelaMax = $('[data-name="max-capacidad-escuela"]').parent();
const auditorioMax = $('[data-name="max-capacidad-auditorio"]').parent();
//First, they are hidden
escuelaMax.hide();
auditorioMax.hide();
//Now, show the correct one
if (montajeVal == "escuela") {
escuelaMax.show();
auditorioMax.hide();
} else if (montajeVal == "auditorio") {
escuelaMax.hide();
auditorioMax.show();
}
//This works only one time :(
//Maybe the JSON should contain data which $montajeVal should be compare with, check that in a loop and then accomplish what I tried to do in the IF statement above
// JSON would be just: ['escuela', 'auditorio']
//I'm using just 2 values for keeping it simple, but in reality there are more.
【问题讨论】: